Convert OneToOneField to MultipleTableInheritance

Building this question: Which is better: foreign keys or model inheritance?

I would like to know if it is possible to replace the OneToOne field with MTI?

Ak

I have:

class GroupUser(models.Model): group = models.OneToOneField(Group) ...other fields.... 

I want too:

 class GroupUser(Group): ...other fields.... 

I think it should be faster or not?

Is it possible?

0
django django-models django-orm
source share
1 answer

It will not be faster, because your parent class object will still have a field in the database that references the child class if you use specific inheritance (and sounds like it would), so technically the efficiency is the same as the OneToOne field .

The choice is also based on business logic. Inheritance is used for situations where you have things of the same type so that you can define common fields / methods in the parent class and reduce some duplicate code. From your example, it sounds like Group and GroupUser - these are absolutely two different things, most likely, they also do not have a lot of common attributes, so if I misunderstand your intention, OneToOneField is the best candidate.

+1
source share

All Articles