Skip to content Skip to sidebar Skip to footer

Django. Proxy Model With Limited Set Of Fields

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 syst

Solution 1:

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.

Post a Comment for "Django. Proxy Model With Limited Set Of Fields"