[Tutor] model methods in Django

Matthew Ngaha chigga101 at gmail.com
Sun May 19 12:35:56 CEST 2013


Thanks guys i had no idea about these  method attributes and also
these underlying oop  __objects__

@ eryksun
i understand your explanation, im still having trouble figuring out
how django is being used in the tutorial.

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?'
    list_filter = ['pub_date']
    search_fields = ['question']
    date_hierarchy = 'pub_date'


if you look at the diagram under that function, why is the value of
"was_published_recently.short_description" the title of that field?
replacing the old title? is a "short_desccription" attribute set
somewhere in django being inactive, but once you make use of this
attribute(or keyword), whatever the value is automatically becomes the
field title? is it the same for boolean being the value of the field
with the checked or unchecked symbol?


More information about the Tutor mailing list