At what point are new ContentTypes created, and how can I trigger this myself?
I have a bunch of migrations, creating new models and such. After that's all done there is a final data migration that assigns the permissions for these new objects to any groups that already have related permissions. (Hereby 'Related permissions' are chosen by me to make sense within the application)
However, the ContentTypes for the newly created models are not available yet when I run that datamigration. They are when I run all other migrations first, and only then run the extra datamigration. I.e. run the command twice. But making that manual patch is not feasable scenario in my case.
So I'd like to manually trigger the creation of ContentTypes for any new models right before I run my datamigration. How is this done?
You should use ContentType.objects.get_for_model()
, which creates the ContentType
instances on demand (it adds some caching as well).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With