Django ORM: Override related_name of Field in Child Class


Similar thing can be done using django's default_related_name meta option.

It might look like an ugly hack, but you can set a function call to the related_name argument instead of string. And then override that function in the child class/model.

class BasePlugin(models.Model):

    def get_ticket_related_name():
        return '%(app_label)s_%(class)s'

    ticket = models.OneToOneField('foobar.ticket', primary_key=True, 

    class Meta(IndexImplementation.Meta):
        abstract = True

class SpecialPlugin(BasePlugin):
    def get_ticket_related_name():
        return 'special'