Monday, April 25, 2016

Re: Django 1.9 Apps aren't loaded yet

Hi James, good to hear you.

It is very good that app initialization is done within a special stage. I remember many problems related to imports and I'm happy that they will not occur anymore.

I understand what is done and what for. Just wondering about possibility to do some kind of late initialization.

I see that models registering is done in metaclasses, I see that app_name is used by model fields to construct related names, and so on... I've tried to move model class registration after app init, but it failed because of lot of early calls for app_name. Let's forget that for a while.

My problem is simple. When I'm developing a reusable app I'd like to expose common/main objects in the package namespace. This is done via imports from package modules. These objects often are not placed in Django modules like models.py. But they are using models via importing them into their module's namespace (typically at the top of the file). This makes chain of imports when you're trying to expose something at the package level. Exposed objects makes high-level interface to the app.

I would like to do same thing using Django 1.9+. I can set app_name explicit, I suppose, I can encapsulate model imports in methods (quite ugly when readability counts), or build proxies.

I'd glad to hear your suggestions for that.

Thanks,
Marcin

--
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-users@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/4740ec50-8381-47f2-9589-0ced04c78509%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment