defining an app stub using AppConfig?

55 views
Skip to first unread message

Eric Abrahamsen

unread,
Nov 25, 2014, 1:50:40 AM11/25/14
to django...@googlegroups.com
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

Collin Anderson

unread,
Nov 26, 2014, 8:44:47 AM11/26/14
to django...@googlegroups.com, gir...@gmail.com
Hi Eric,

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

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

Collin

Eric Abrahamsen

unread,
Nov 30, 2014, 8:36:33 PM11/30/14
to django...@googlegroups.com
Collin Anderson <cmawe...@gmail.com> writes:

> Hi Eric,
>
> I'm not sure, but is this what you want?
>
> models = apps.get_app_config(setting.NEWSLETTER_APP).models_module
>
> Collin

Thanks Collin. I think that would do what I want, but in the end I
decided the easier way to go would be to fork the app, then experiment
with switching code in the app itself, rather than switching apps in my
Django project. Whether or not that will actually turn out to be simpler...
Reply all
Reply to author
Forward
0 new messages