That is fascinating. I have been thinking about a way of handling our product categories so that we could have better data validation on certain "fields" within a part category. However, I have been leaning more towards having a comma separated list or PostgreSQL ArrayField to store the multiple fields per category. In the database, though, the final product would be saved as a comma separated list in a text field with the corresponding values. I should ponder these virtual models a little more before settling on what to do.
-----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Vijay Khemlani Sent: Thursday, January 5, 2017 4:00 PM To: [email protected] Subject: Re: Dynamic Models "That was exacly the points i'm willing to avoid. Had any problems with the metaclass approach? Why did you chose the "virtual model" concept?" We had to represent multiple product categories, each with their own structure and particular fields. In the end we had around 700 virtual models, which would've been a little insane for Django models. On 1/5/17, Michal Petrucha <[email protected]> wrote: > On Wed, Jan 04, 2017 at 06:38:54PM -0200, Guilherme Leal wrote: >> Is there a way to populate Django model cache on the fly? >> I was thinking about saving the model definition on some backend >> (database for instance) and loading as needed. This way we can >> basically build a custom admin interface for the model definitions, >> and load the models (through "type()" or something similar) into the >> cache "on the fly". >> >> Guilherme Leal > > Hi Guilherme, > > I kinda got lost deeper in the reply chain in this thread, but > regarding the original question, have you had a look at > https://djangopackages.org/grids/g/dynamic-models/ ? django-mutant, in > particular, seems to be quite close to what you're asking for. Even if > it's not a direct solution for you, you might be able to take a lot of > inspiration from there. > > However, keep in mind that any kind of dynamic runtime model > registration involves heavy usage of Django internals, which means it > will be fragile, and likely to break with each new minor release of > Django. Also, there are many parts of the ORM that kind of just assume > that models are static throughout the lifetime of a Python process, > with all kinds of field caching, but also things like the way > relationship fields are resolved on startup. So even if you put > something together that appears to kind of work, expect there to be a > lot of corner cases and things that outright won't work. > > Good luck, > > Michal > > -- > You received this message because you are subscribed to the Google > Groups "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/20170105200033.GH1628%40koniiiik.org. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei1130Az29c-oS-AeKmAVL1z%2BXtoYkZJx68pCv4b-ATzew%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3f803387e2434321adc2270cebd6b533%40ISS1.ISS.LOCAL. For more options, visit https://groups.google.com/d/optout.

