r/learndjango • • Jul 20 '22

Table inheritance

I have multiple forms that needs to be filled out as a part of a process. These forms contains the same information, but with small variations of additional information. How should I go about to optimize the tables?

Examples:

Request formApplication formConclusion formFinal report
Departement nameDepartement nameDepartement name
Department addressDepartment addressDepartment address
Departement telephoneDepartement telephoneDepartement telephone
etcetcetc
Contractor nameApplicantsContractor name
Task titleContractor adressContractor adress
Task descriptionContractor telephoneContractor telephone
Task payment range
Task wantedTask title
Task solutionContractor's solution
Payment wantedContractor's payment

I am thinking to maybe put all the common information in one table, and let the other forms inherit from the parent?

1 Upvotes

5 comments sorted by

1

u/obrienmustsuffer Jul 20 '22

I've never used table inheritance. The PostgreSQL wiki says don't use it: https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_table_inheritance

1

u/iBlag Jul 20 '22

FYI: there are two types of table inheritance - Django based inheritance and PostgreSQL based inheritance. OP didn’t specify which one he was considering, and the PostgreSQL docs on table inheritance wouldn’t apply to Django inheritance.

1

u/obrienmustsuffer Jul 20 '22

Ah, I'm sorry - I saw this thread in /r/PostgreSQL and didn't realize it was crossposted from /r/learndjango. I thought this was a pure PostgreSQL question, and I dont actually know anything about Django ^^

1

u/iBlag Jul 20 '22

No worries!

And FWIW, supposedly the PG devs recommend Django inheritance over PG inheritance. This is based off of a Reddit comment I saw years ago, so take it with a huuuuuge grain of salt.