get ContentType with django get_model 1

get ContentType with django get_model

apps.get_model('contenttypes', 'ContentType')

Here is what the above code is Doing:
1. We’re importing the ContentType model from the contenttypes app.
2. We’re getting the ContentType for the model we’re using.
3. We’re getting the object ID for the specific object we’re using.
4. We’re getting the actual object we’re using.
5. We’re creating a new Comment object with the data we want.
6. We’re saving the comment to the database.

Similar Posts