Main moment - database scheme is not designed from scratch. It's inherited from legacy system and must be left as is at the moment, because it's also shared with some external systems. So we have kind of:
class A(models.Model):
"""
List of 110 fields
"""
field_1 = models.CharField()
field_... = models.CharField()
field_n = models.CharField()
Are there any way to have model B, which will be proxy model and will have limited set of fields?
Like:
class B(A):
class Meta:
proxy = True
field_3 = models.CharField()
field_5 = models.CharField()
field_10 = models.CharField()
The only solution, that I have in mind currently - create some unmanaged models. But proxy models look better for this goal.. or not?
According to the docs, proxy model isn't what you are looking for
So, the general rules are:
If you are mirroring an existing model or database table and don’t want all the original database table columns, use Meta.managed=False. That option is normally useful for modeling database views and tables not under the control of Django.
If you are wanting to change the Python-only behavior of a model, but keep all the same fields as in the original, use Meta.proxy=True. This sets things up so that the proxy model is an exact copy of t he storage structure of the original model when data is saved.
Your best bet is to create a view in SQL listing only the fields that you want and then use an unmanaged table to connect to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With