Changes between Initial Version and Version 1 of Ticket #32833


Ignore:
Timestamp:
Jun 9, 2021, 3:47:10 PM (3 years ago)
Author:
HMaker
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32833 – Description

    initial v1  
    1818}}}
    1919it works when I pass a single model to `ContentType.objects.get_for_models()`, but `get_for_models()` is supposed to work with multiple models.
     20
     21EDIT:
     22Adding `model_class()` to `ContentType` makes it work
     23
     24{{{
     25def create_normal_users_group(apps, *args):
     26    auth = SimpleNamespace(**apps.all_models['auth'])
     27    myapp = SimpleNamespace(**apps.all_models['myapp'])
     28    ContentType = apps.get_model('contenttypes', 'ContentType')
     29    # this makes it work =========================
     30    def model_class(self):
     31        return apps.get_model(self.app_label, self.model)
     32    ContentType.model_class = model_class
     33    # ========================================
     34    group = auth.group.objects.create(name='Normal Users')
     35    contenttypes = ContentType.objects.get_for_models(myapp.user, myapp.proxy) # there are more models...
     36   # ...
     37}}}
Back to Top