Hi Adam,

Migrations build a fake app registry containing fake app configs for each state 
of the models.

They implement a small subset of features of the real app configs.

See 
https://github.com/django/django/blob/5e32605/django/db/migrations/state.py#L119-L131

That’s why my_app_config.models_module is None in your example.

-- 
Aymeric.



> On 31 déc. 2014, at 06:01, Adam Venturella <[email protected]> wrote:
> 
> Attempting this approach, calling :
> 
> create_permissions(my_app_config)
> 
> from within my migration fails to create the permissions. It looks like 
> create_permissions checks for models_module on the provided app config. 
> However, when my migration runs, my models_module is None. 
> 
> So is there a better time when models_module is available?  My understanding 
> of models_module is that I have a models.py in my app, which I indeed do. I 
> can call 
> 
> my_app_config.get_models()
> 
> and I get a list of all of my models, but my_app_config.models_module remains 
> None
> 
> If I try this from the django shell:
> 
> from django.apps import apps
> apps.get_app_config('my_app').models_module
> 
> 
> The result here is not None, so it seems the issue is migration related.
> 
> 
> 
> 
> On Tuesday, October 14, 2014 7:09:55 PM UTC-7, Andrew Godwin wrote:
> As the ticket suggests, you can call the function to create permissions 
> yourself in the data migration, and then you can assign them as normal. 
> There's no need to use fixtures (in fact, migrations are better without 
> fixtures, as there's no easy way to load them).
> 
> Andrew
> 
> On Tue, Oct 14, 2014 at 6:56 PM, Michael <[email protected] 
> <javascript:>> wrote:
> Hi,
> 
> Since the permissions are not yet created when the migrations are run, it is 
> not possible to have a data migration that creates a group and assigns 
> permissions.
> 
> Based on this ticket: https://code.djangoproject.com/ticket/23422 
> <https://code.djangoproject.com/ticket/23422>, I understand there will not be 
> a fix. Do you recommend to keep using an initial fixture to create a group?
> 
> Thanks
> Michael
> 
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected] 
> <javascript:>.
> Visit this group at http://groups.google.com/group/django-developers 
> <http://groups.google.com/group/django-developers>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-developers/cce3b138-6524-417c-b05e-cd3c25742e3b%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-developers/cce3b138-6524-417c-b05e-cd3c25742e3b%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/django-developers 
> <http://groups.google.com/group/django-developers>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-developers/ca2a503a-bdbc-4280-b401-02a2c94cfaa6%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-developers/ca2a503a-bdbc-4280-b401-02a2c94cfaa6%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/9733BADE-1941-4449-8A32-6AF09D1C5099%40polytechnique.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to