Z
Z
zkweb2016-11-21 13:29:13
Django
zkweb, 2016-11-21 13:29:13

Dajngo - how to use one table for two models?

New to django. It is necessary to use one table, but the goals are different + different managers. Therefore, the question arose, to create a copy of the model (that is, to register all the fields) or to somehow inherit? Tell me the right way.
I use class-based views

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Peter, 2016-11-21
@zkweb

Probably you need a proxy-model

A
Artyom Innokentiev, 2016-11-21
@artinnok

You most likely have the wrong architecture.
1 table for two different models is a bad decision.
1 model - 1 table.
Why is that bad?
1. The code is written in order to be easy to read - especially in python.
2. Imagine that in 3 years you or another proger will open your project - how quickly will he understand this implicit trick with 1 table for 2 models?
3. Don't go all out - redefining managers is tricky stuff, try to get a good base in Django first.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question