[Tutor] model methods in Django

Matthew Ngaha chigga101 at gmail.com
Sun May 19 16:23:27 CEST 2013


> class Poll(models.Model):
>
>     question = models.CharField(max_length=200)
>     pub_date = models.DateTimeField('date published')
>
>
>
>     def was_published_recently(self):
>         return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
>
>     #
>
>
>     was_published_recently.admin_order_field = 'pub_date'
>     was_published_recently.boolean = True
>     was_published_recently.short_description = 'Published recently?'
>
>
> Source:
> https://docs.djangoproject.com/en/dev/intro/tutorial01/
> https://docs.djangoproject.com/en/dev/intro/tutorial02/
>
>
> I find the Django (and this fragment) very elegant UP TO the comment.
>
is the dislike after the comment more to do with the python code
rather than django itself?


More information about the Tutor mailing list