For the benefit of others,I believe the full class (from the Django
Tutorial) is
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.
On Sat, May 18, 2013 at 8:16 PM, Matthew Ngaha <[email protected]> wrote:
> im following the official docs and after learning Python im sure of
> how methods work, but the model example on the beginners guide has me
> really confused.
>
> The model definition is omitted but can anyone explain how this methed
> (was_published_recently) is given these attributes:
>
> class Poll(models.Model):
> # ...
> 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?'
>
> are the names of the attributes already attached to these
> functions/methods, or are they being created on the fly with whatever
> name you want? As i am unable to comprehend what is going on, i dont
> really have a clue as to what each definition is doing and how it
> affects the model, even after reading this section of the docs over
> and over again im still lost.
> _______________________________________________
> Tutor maillist - [email protected]
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor