url(r'^news/(?P(\d){8})?(\-)?(?P(\d)+)?$', news_views.show_news, name="news-url"),
models.py:
class News(models.Model):
...........
def get_absolute_url(self):
return "/news/%s" % (self.news_date.strftime('%Y%m%d') + '-' + str(self.id))
template.html:
{{ news.title }}
class UserProfileForm(ModelForm):
def __init__(self, *args, **kwargs):
super(UserProfileForm, self).__init__(*args, **kwargs)
try:
country_id = self.instance.country.id
self.fields['city'].queryset = City.objects.filter(country=country_id)
except:
pass
class Meta:
model = UserProfile
exclude = ('deleted', 'deletion_date', 'blocked_until', 'activation_key', 'blocked_times', 'test_fails',)
* This source code was highlighted with Source Code Highlighter.