#32833: ContentType.objects.get_for_models() in migrations does not works for
multiple models
------------------------------------------------+------------------------
               Reporter:  Heraldo Lucena        |          Owner:  nobody
                   Type:  Bug                   |         Status:  new
              Component:  contrib.contenttypes  |        Version:  3.1
               Severity:  Normal                |       Keywords:
           Triage Stage:  Unreviewed            |      Has patch:  0
    Needs documentation:  0                     |    Needs tests:  0
Patch needs improvement:  0                     |  Easy pickings:  0
                  UI/UX:  0                     |
------------------------------------------------+------------------------
 I am trying to use migrations to create default groups, I tried to run the
 following procedure with `migrations.RunPython()`

 {{{
 def create_normal_users_group(apps, *args):
     auth = SimpleNamespace(**apps.all_models['auth'])
     myapp = SimpleNamespace(**apps.all_models['myapp'])
     ContentType = apps.get_model('contenttypes', 'ContentType')
     group = auth.group.objects.create(name='Normal Users')
     contenttypes = ContentType.objects.get_for_models(myapp.user,
 myapp.proxy) # there are more models...
    # ...
 }}}
 but it raises `AttributeError`

 {{{
   File "/home/user/projects/myapp/.venv/lib/python3.8/site-
 packages/django/contrib/contenttypes/models.py", line 89, in
 get_for_models
     opts_models = needed_opts.pop(ct.model_class()._meta, [])
 AttributeError: 'ContentType' object has no attribute 'model_class'
 }}}
 it works when I pass a single model to
 `ContentType.objects.get_for_models()`, but `get_for_models()` is supposed
 to work with multiple models.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32833>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.df6f3cce884f08578eca6b048d287256%40djangoproject.com.

Reply via email to