Dynamic Models

85 views
Skip to first unread message

Guilherme Leal

unread,
Jan 4, 2017, 3:39:14 PM1/4/17
to django...@googlegroups.com
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

Avraham Serour

unread,
Jan 5, 2017, 9:35:15 AM1/5/17
to django-users
I guess you could play with metaclasses and generate the class definition on runtime using information from the database

But why? You can save the model definition on files, why saving them to database and complicate your life?

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/CAOs3Lp7_R4RK%3DVconoQ1W6rzK8xYaiVJX-FHtyZ3Cxg4MmbOow%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Guilherme Leal

unread,
Jan 5, 2017, 10:33:07 AM1/5/17
to django...@googlegroups.com
My idea was to build an user interface for the model definition, so the developer (or in this case, the user) could define the model using a register form.

Like a user interface to define the model layer, I gess.

Beautifulloop

unread,
Jan 5, 2017, 10:54:02 AM1/5/17
to Django users
I think you just need to define a generic model. I dont see how what you are asking is feasible since it would require that (on the fly that migrations are made). You can write a generic model where the types can be represented by a field name.


On Thursday, 5 January 2017 17:33:07 UTC+2, Guilherme Leal wrote:
My idea was to build an user interface for the model definition, so the developer (or in this case, the user) could define the model using a register form.

Like a user interface to define the model layer, I gess.
2017-01-05 12:34 GMT-02:00 Avraham Serour <tov...@gmail.com>:
I guess you could play with metaclasses and generate the class definition on runtime using information from the database

But why? You can save the model definition on files, why saving them to database and complicate your life?
On Wed, Jan 4, 2017 at 10:38 PM, Guilherme Leal <leal...@gmail.com> 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

--
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 django-users...@googlegroups.com.

--
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 django-users...@googlegroups.com.

Guilherme Leal

unread,
Jan 5, 2017, 11:03:10 AM1/5/17
to django...@googlegroups.com
The "migrations on the fly" thing dont get to be a problem (since I gess we could call the migrations api to generate the migration).
My concenrs would be contructing and refreshing the model cache (I say the "model cache" like the list accessed through django.apps.get_models() ), and the OBVIOUS performance issues that could be generated.

Anyway, EVEN if it turns out to be impratical to production, i want to build it as a proof of concept, and see where it can go, so any help or ideias would be apreciated!

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Avraham Serour

unread,
Jan 5, 2017, 11:06:08 AM1/5/17
to django-users
you should read about metaclasses, basically it enables you to build class definitions in runtime.



Guilherme Leal

unread,
Jan 5, 2017, 11:20:51 AM1/5/17
to django...@googlegroups.com
I know metaclasses, and i know that the django models uses some "meta class magic" to register the models on the model cache.
I gess i need to test the implication of refreshing the model cache on the fly, since it doesn't have a "natural" way to refresh itself.

Vijay Khemlani

unread,
Jan 5, 2017, 1:13:05 PM1/5/17
to django...@googlegroups.com
I had to implement dynamic models for our project.

In the end we represented them in four django models, two for the
"virtual models" and its fields and two for the actual data

We used the django model system for these four base classes, but the
"virtual models" on top of them were custom (so no django orm, all
queries included joins, etc etc)

Our solution to that was to index the important data in ElasticSearch
and execute the queries there

Pros:
- Completely dynamic
- Does not depend on metaprogramming or Django's models
- Querying via ElasticSearch is not so bad and is quite fast

Cons:
- Quite slow when you need to update data in the database
- No ORM unless you implement it
- You have to be careful keeping the index entries updated when needed
- Limited to basic data types (int, char, decimal, date, file)
- No DB integrity checks
>>>>>>> <https://groups.google.com/d/msgid/django-users/CAOs3Lp7_R4RK%3DVconoQ1W6rzK8xYaiVJX-FHtyZ3Cxg4MmbOow%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>>>> .
>>>>>>> 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 django-users...@googlegroups.com.
>>>>>> To post to this group, send email to django...@googlegroups.com.
>>>>>> 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/CAFWa6t%2B5DO
>>>>>> 5u8p5fRrGAGkW1KYR2DZxc_wtkNQG7bX3u6v7JuA%40mail.gmail.com
>>>>>> <https://groups.google.com/d/msgid/django-users/CAFWa6t%2B5DO5u8p5fRrGAGkW1KYR2DZxc_wtkNQG7bX3u6v7JuA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>> 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 django-users...@googlegroups.com.
>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>> gid/django-users/e00f8c04-8c97-4827-9555-e155c4afd20a%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/e00f8c04-8c97-4827-9555-e155c4afd20a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> 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 django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/CAOs3Lp5V2Le%3DJWbSSp_%2B%2BsXK4KaN_3rB7-BV
>>> Hk6OSE8SgKoYFw%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAOs3Lp5V2Le%3DJWbSSp_%2B%2BsXK4KaN_3rB7-BVHk6OSE8SgKoYFw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> 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 django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> 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/CAFWa6tKZcZLQ1BL7YhEqJpmmkv-
>> KLoxcRiMyMaTHsu7s3%2BA5%3DA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAFWa6tKZcZLQ1BL7YhEqJpmmkv-KLoxcRiMyMaTHsu7s3%2BA5%3DA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> 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 django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> 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/CAOs3Lp6CPMUMAJfeRQFw0ihV7Ve3ggTWW0rL%3D4Q_V50bf4QEOA%40mail.gmail.com.

ludovic coues

unread,
Jan 5, 2017, 1:26:47 PM1/5/17
to django...@googlegroups.com
Would it work if the interface provide a download for a bunch of
models.py file ?
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei3VYWEjK02v9yd13NPk_cFn7x1RAHhT3yyiq_J4azX-jg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

Guilherme Leal

unread,
Jan 5, 2017, 1:26:47 PM1/5/17
to django...@googlegroups.com
@Vijay Khemlani
- No ORM unless you implement it
- No DB integrity checks

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?


>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>> gid/django-users/e00f8c04-8c97-4827-9555-e155c4afd20a%40googlegroups.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

>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> .
>>>
>>> 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

>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/
>> .
>>
>> 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

> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> 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 django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Guilherme Leal

unread,
Jan 5, 2017, 1:29:26 PM1/5/17
to django...@googlegroups.com
@ludovic coues
Like what? let the interface generate the python models? I thought about that, but it doesnt seem viable. Have any ideias?


>>>>> To post to this group, send email to django...@googlegroups.com.
>>>>> Visit this group at https://groups.google.com/group/django-users.
>>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>>> gid/django-users/e00f8c04-8c97-4827-9555-e155c4afd20a%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/django-users/e00f8c04-8c97-4827-9555-e155c4afd20a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>> 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

>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>> gid/django-users/CAOs3Lp5V2Le%3DJWbSSp_%2B%2BsXK4KaN_3rB7-BV
>>>> Hk6OSE8SgKoYFw%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAOs3Lp5V2Le%3DJWbSSp_%2B%2BsXK4KaN_3rB7-BVHk6OSE8SgKoYFw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> 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

>>> To post to this group, send email to django...@googlegroups.com.
>>> 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/CAFWa6tKZcZLQ1BL7YhEqJpmmkv-
>>> KLoxcRiMyMaTHsu7s3%2BA5%3DA%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAFWa6tKZcZLQ1BL7YhEqJpmmkv-KLoxcRiMyMaTHsu7s3%2BA5%3DA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> 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

>> To post to this group, send email to django...@googlegroups.com.
>> 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/CAOs3Lp6CPMUMAJfeRQFw0ihV7Ve3ggTWW0rL%3D4Q_V50bf4QEOA%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 django-users+unsubscribe@googlegroups.com.
--

Cordialement, Coues Ludovic
+336 148 743 42
--
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 django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Matthew Pava

unread,
Jan 5, 2017, 1:58:53 PM1/5/17
to django...@googlegroups.com

Going down that route, we would basically be developing an IDE for Django models.  It would definitely be possible, but it would involve a lot of work.  Maybe it could even be integrated into django-admin one day.

 

You may want to check out http://www.web2py.com/ which does its own web IDE for Python including its models, though it’s not Django.

>>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>>> gid/django-users/e00f8c04-8c97-4827-9555-e155c4afd20a%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/django-users/e00f8c04-8c97-4827-9555-e155c4afd20a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>> 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 django-users...@googlegroups.com.
>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.

>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>> gid/django-users/CAOs3Lp5V2Le%3DJWbSSp_%2B%2BsXK4KaN_3rB7-BV
>>>> Hk6OSE8SgKoYFw%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAOs3Lp5V2Le%3DJWbSSp_%2B%2BsXK4KaN_3rB7-BVHk6OSE8SgKoYFw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> 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 django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> 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/CAFWa6tKZcZLQ1BL7YhEqJpmmkv-
>>> KLoxcRiMyMaTHsu7s3%2BA5%3DA%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAFWa6tKZcZLQ1BL7YhEqJpmmkv-KLoxcRiMyMaTHsu7s3%2BA5%3DA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> 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 django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> 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/CAOs3Lp6CPMUMAJfeRQFw0ihV7Ve3ggTWW0rL%3D4Q_V50bf4QEOA%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 django-users...@googlegroups.com.


> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.

--

Cordialement, Coues Ludovic
+336 148 743 42

--
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 django-users...@googlegroups.com.


To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Guilherme Leal

unread,
Jan 5, 2017, 2:07:00 PM1/5/17
to django...@googlegroups.com
@Matthew Pava
>Going down that route, we would basically be developing an IDE for Django models

Well, thinking about it, we can say that literally IS an IDE for Django.

That's my goal at least. (actually, i'm wishing to use graphene for graphql exposition of default manager too)

Anyone interested?
Or should I ask, "would someone use it if it came to life?"


>>>>> To post to this group, send email to django...@googlegroups.com.
>>>>> Visit this group at https://groups.google.com/group/django-users.
>>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>>> gid/django-users/e00f8c04-8c97-4827-9555-e155c4afd20a%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/django-users/e00f8c04-8c97-4827-9555-e155c4afd20a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>> 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


>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>> gid/django-users/CAOs3Lp5V2Le%3DJWbSSp_%2B%2BsXK4KaN_3rB7-BV
>>>> Hk6OSE8SgKoYFw%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAOs3Lp5V2Le%3DJWbSSp_%2B%2BsXK4KaN_3rB7-BVHk6OSE8SgKoYFw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> 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


>>> To post to this group, send email to django...@googlegroups.com.
>>> 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/CAFWa6tKZcZLQ1BL7YhEqJpmmkv-
>>> KLoxcRiMyMaTHsu7s3%2BA5%3DA%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAFWa6tKZcZLQ1BL7YhEqJpmmkv-KLoxcRiMyMaTHsu7s3%2BA5%3DA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> 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


>> To post to this group, send email to django...@googlegroups.com.
>> 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/CAOs3Lp6CPMUMAJfeRQFw0ihV7Ve3ggTWW0rL%3D4Q_V50bf4QEOA%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 django-users+unsubscribe@googlegroups.com.

--

Cordialement, Coues Ludovic
+336 148 743 42

--
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 django-users+unsubscribe@googlegroups.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 django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

--
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 django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Matthew Pava

unread,
Jan 5, 2017, 2:13:20 PM1/5/17
to django...@googlegroups.com

It does sound like a fun and exciting project.  Unfortunately, I rarely use the admin, and I don’t see myself using it to enter new models.  However, as I type this, I might be convinced to use it.  I currently use PyCharm as my IDE for Django development, and it’s decent.

 

From: django...@googlegroups.com [mailto:django...@googlegroups.com] On Behalf Of Guilherme Leal
Sent: Thursday, January 5, 2017 1:06 PM
To: django...@googlegroups.com
Subject: Re: Dynamic Models

 

@Matthew Pava

>Going down that route, we would basically be developing an IDE for Django models

 

Well, thinking about it, we can say that literally IS an IDE for Django.

 

That's my goal at least. (actually, i'm wishing to use graphene for graphql exposition of default manager too)

 

Anyone interested?

Or should I ask, "would someone use it if it came to life?"

2017-01-05 16:57 GMT-02:00 Matthew Pava <Matthe...@iss.com>:

Going down that route, we would basically be developing an IDE for Django models.  It would definitely be possible, but it would involve a lot of work.  Maybe it could even be integrated into django-admin one day.

 

You may want to check out http://www.web2py.com/ which does its own web IDE for Python including its models, though it’s not Django.

 

>>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>>> gid/django-users/e00f8c04-8c97-4827-9555-e155c4afd20a%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/django-users/e00f8c04-8c97-4827-9555-e155c4afd20a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>> 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 django-users...@googlegroups.com.
>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.

>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>> gid/django-users/CAOs3Lp5V2Le%3DJWbSSp_%2B%2BsXK4KaN_3rB7-BV
>>>> Hk6OSE8SgKoYFw%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAOs3Lp5V2Le%3DJWbSSp_%2B%2BsXK4KaN_3rB7-BVHk6OSE8SgKoYFw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> 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 django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> 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/CAFWa6tKZcZLQ1BL7YhEqJpmmkv-
>>> KLoxcRiMyMaTHsu7s3%2BA5%3DA%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAFWa6tKZcZLQ1BL7YhEqJpmmkv-KLoxcRiMyMaTHsu7s3%2BA5%3DA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> 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 django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> 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/CAOs3Lp6CPMUMAJfeRQFw0ihV7Ve3ggTWW0rL%3D4Q_V50bf4QEOA%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 django-users...@googlegroups.com.


> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.

--

Cordialement, Coues Ludovic
+336 148 743 42

--
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 django-users...@googlegroups.com.


To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

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 django-users...@googlegroups.com.


To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.


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 django-users...@googlegroups.com.


To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.


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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Michal Petrucha

unread,
Jan 5, 2017, 3:01:15 PM1/5/17
to django...@googlegroups.com
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
signature.asc

Vijay Khemlani

unread,
Jan 5, 2017, 5:00:04 PM1/5/17
to django...@googlegroups.com
"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.
> --
> 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 django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> 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.

Matthew Pava

unread,
Jan 5, 2017, 5:18:14 PM1/5/17
to django...@googlegroups.com
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: django...@googlegroups.com [mailto:django...@googlegroups.com] On Behalf Of Vijay Khemlani
Sent: Thursday, January 5, 2017 4:00 PM
To: django...@googlegroups.com
Subject: Re: Dynamic Models

To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei1130Az29c-oS-AeKmAVL1z%2BXtoYkZJx68pCv4b-ATzew%40mail.gmail.com.

Guilherme Leal

unread,
Jan 6, 2017, 6:32:45 AM1/6/17
to django...@googlegroups.com
@Michal Petrucha
That was one of the insights that I've been wanted.

One way or another I will try, but will keep in mind these points. Thank you!

Jani Tiainen

unread,
Jan 10, 2017, 2:59:30 AM1/10/17
to django...@googlegroups.com

Hi,

You're probably after EAV pattern (or anti-pattern depending who you ask).

Implementing that in Django is relatively trivial, though with any kind of dynamics you'll going to loose most of the ORM goodies.

This kind of leads to question that is Django ORM really needed for you at all? How about having NoSQL databases like ArangoDB to handle all the dynamics?

--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.

-- 
Jani Tiainen

Guilherme Leal

unread,
Jan 10, 2017, 6:10:27 AM1/10/17
to django...@googlegroups.com
@Jani Tiainen
I really like Django ORM, and will make everything possible to keep it. I think that losing the ORM will make things harder in the big picture because it would make the logic built by the developers a lot more error prone and not "database agnostic" (at least as far as thedatabases backend suported by django go).

But thanks for the ideia, will certainly look for ArangoDB.

2017-01-10 5:58 GMT-02:00 Jani Tiainen <red...@gmail.com>:

Hi,

You're probably after EAV pattern (or anti-pattern depending who you ask).

Implementing that in Django is relatively trivial, though with any kind of dynamics you'll going to loose most of the ORM goodies.

This kind of leads to question that is Django ORM really needed for you at all? How about having NoSQL databases like ArangoDB to handle all the dynamics?


On 04.01.2017 22:38, 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
--
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 django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

-- 
Jani Tiainen

--
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 django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Jani Tiainen

unread,
Jan 10, 2017, 6:34:22 AM1/10/17
to django...@googlegroups.com

Problem, as you see is that Django is build for static models. So if you have a dynamic model, how would you construct (efficient) queries in your other views unless you know the structure of the data?

Well you kind of can't since there is no structure. Also, what purpose would such a models serve? I'm just trying to figure out what kind of system you're thinking to allow arbitrary ad-hoc models to be built? (What's the real world use case)
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.

-- 
Jani Tiainen

Guilherme Leal

unread,
Jan 10, 2017, 7:39:45 AM1/10/17
to django...@googlegroups.com
Well, some more context then:

I've worked at a company that have exactly the same logic writen in perl and using an ORM built inside the company. The ideia was to build a plataform to interact with the DB, and with this interaction, extend the information about the table been created/modified or the field been created/modified, and with that, build web views and forms dynamically from that extended schema. The business logic was entirely in database triggers, and javascript (one of the extensions of the fields information was that it was possible to write javascript events, and the plataform binded that event to the view).
Needless to say, everithing was heavly cached: everytime the schema (or the extended schema) was updated, it was serialized and cached in a redis environment, so it was always ready to query.

It worked preaty well, and was a tool good to work with.

So i thought: "well, i gess that can built with django!".

And here I am. :)

Any questions, I'm always aviable.
Thanx!
Reply all
Reply to author
Forward
0 new messages