Wednesday, November 26, 2014

Re: defining an app stub using AppConfig?

Hi Eric,

I'm not sure, but is this what you want?

models = apps.get_app_config(setting.NEWSLETTER_APP).models_module

Collin


On Tuesday, November 25, 2014 1:50:40 AM UTC-5, Eric Abrahamsen wrote:
I'm messing around with testing many Github forks of the emencia
newsletter app, looking for one I like. In the meantime (and as I'm
likely to continue switching around for a while), I'd like not to have
to commit code that points at the different names of the different apps:
they all have the same models and database structure, the only thing
that changes is the top-level name of the module.

I looked at the code for contrib/comments, and have some questions about
using AppConfig.

What I'd like to do is have a setting in settings.py that reads:

NEWSLETTER_APP='maja_newsletter'

Or what have you. This would change semi-regularly as I test.

Then I'd have a top-level file called newslettermodule.py, with
something like this in it:

from django.conf import settings
from django.apps import apps

module = apps.get_app_config(settings.NEWSLETTER_APP.rpartition(".")[2]).module


Here's where I'm having trouble. Is there any way that I can basically
dump all the models from what would be module.models into this file?
Playing with this in the shell, when I try to import actual models from
module.models I get an "No module named module.models", even though
eval'ing "module.models" directly gives me:

<module 'maja_newsletter.models' from '/path/'>

Clearly this is just a misunderstanding on my part about how Python
modules work.

Is there anything I can do? Looking at the code in contrib/comments I
suspect not -- if there were, it would have been done there.

Anyway, thanks for any light shed on how AppConfig can be used in this
situation...

Eric

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0ef058df-3f87-4b5f-877a-25fc6ff5164b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment