pythondjangophotologue

Where Photologue's Photo.get_previous_by_date_added() method defined?


Definition of Photologue model Photo doesn't contain method get_previous_by_date_added, as well as its parent model ImageModel. ImageModel inherits from django models.Model base class which hasn't this method too.

But there is usage of this method in Photo model:

class Photo:
...
    def get_previous_in_gallery(self, gallery):
        try:
            return self.get_previous_by_date_added(galleries__exact=gallery,
                                                   is_public=True)
        except Photo.DoesNotExist:
            return None
...

Where its definition lives? (link to Photologue models.py)


Solution

  • It's added by the contribute_to_class method of DateField, as documented in the model instance reference - see also the code of django.db.models.fields.__init__.

    A lot of Django's model attributes are added by metaclasses or by external classes, so it doesn't always help to look directly at the models.Model source.