DEV Community

Discussion on: Using abstract models in Django

Collapse
 
kirancapoor94 profile image
Kiran Capoor

As per what I’ve observed, abstract models aren’t written in the DB. So there’s no Table for an abstract model.

The Django ORM, maps the fields to each model it’s subclassing only at the time of migrations.

However, when in the case of Inheritance, Django ORM fails miserably. N+1 queries, INNER JOINS are way too common which ultimately make the DB Queries VERY slow.

My recommendation is to use Abstract Tables only when needed, and avoid Inheritance completely when developing using Django. Instead use OneToOne/ForeignKey relationships to extend the tables.

Thanks 🍻

Collapse
 
guzmanojero profile image
guzmanojero

I don't follow what you're saying.

If an abstract model isn't creating tables you don't have a N+1 issue.

I've commented here:
dev.to/guzmanojero/comment/2ac2g

Can you expand?