[Django]-Is there a way to auto-increment a Django field with respect to a foreign key?

10👍

You can do this:

def save(self, force_insert=False, force_update=False):
    #if self.id is None:
    self.version_number += 1

    super(EntryVersion, self).save(force_insert, force_update) # Call the "real" save() method.

which comes directly from here:

http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods

👤Tiago

Leave a comment