Start point of dynmanic models creation.

29 views
Skip to first unread message

Vlasov Vitaly

unread,
Oct 19, 2016, 7:19:57 AM10/19/16
to Django users
Hello.

I have working model factory of dynamic models in my app.models.py. I need to know where i should call it in my code. Right now i call it in MyAppConfig ready() method and think it is not right way. But this is working.
Where i should place dynamic models factory call?

Jani Tiainen

unread,
Oct 19, 2016, 7:28:15 AM10/19/16
to django...@googlegroups.com

Well problem with Django is that there is not really support for "dynamic models".

Django expects that _before_ calling ready() all models are registered and ready for use.

Also note that ready() maybe called multiple times. You should take into account that for example when running unit tests Django changes database connection, which may affect your model construction.

--
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/492d62ac-5dd4-4553-a4e9-66798f51a131%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
Jani Tiainen

Vlasov Vitaly

unread,
Oct 20, 2016, 4:34:37 AM10/20/16
to Django users
Yes. I know how django works with dynamic models and this make me sad.

Yes, i know workflow of AppConfigs init. It set models_ready and ready booleans and call AppConfig.ready() then.

I really can't understand why AppConfig.ready() is calling multiple times. This is strange. But this can be fixed by some AppConfig state attribute. (like self.dynamic_models_ready). Anyway my models is unmanaged and can't(i hope) be affected.

May be AppConfig class should have models_ready() method for overwriting. It will be called after setting app models. Actually i can realize this in Django but not sure about neediness...

среда, 19 октября 2016 г., 14:28:15 UTC+3 пользователь Jani Tiainen написал:
Reply all
Reply to author
Forward
0 new messages