Related names are provided by Django ORM so you can easily find all the models that are part of the current model. Therefore, if you have a key to Foo to Bar, the Bar instance will default to the foo_set attribute, which will provide you with a list of all the Foos associated with this particular bar.
You can specify your own connection_name to make the code easier to read, with more natural / relevant related names.
However, as you can see, Django ORM requires unique values ββfor the associated names, and since you have an FK in your base class, it automatically creates these FKs for all child models and uses the same name for them, which is not viable .
Good news: this documentation note shows a workaround for Django 1.2+
If for some reason you need to use Django 1.1 or earlier, here is an alternative solution: instead of using FK in the abstract model, just use the pk storage field for the model with keys and add accessors accordingly. eg:
class AuditBase(models.Model): created_at = models.DateTimeField("Created at", auto_now_add=True) created_by = models.IntegerField(required=True) updated_at = models.DateTimeField("Updated at", auto_now=True) updated_by = models.IntegerField(required=True) class Meta: abstract = True @property def creator(self): return User.objects.get(id=self.created_by) @property def last_editor(self): return User.objects.get(id=self.updated_by) def save(self, *args, **kwargs):
source share