[Django]-Getting the primary key of related object with inherited model in Django

2👍

b has two attibutes,

b.a_ptr and b.a_ptr_id

👤second

1👍

You can control the name if you specify a OneToOneField on B with parent_link=True. For example:

class A(TranslatableModel):
    translations = TranslatedFields(
        name = models.CharField(max_length=30)
    )
    f = IntegerField()

class B(A):
    link_back_to_A = OneToOneField(A, parent_link=True) # specify the name
    some_field = ...

See: https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.OneToOneField

Leave a comment