django content types – how to get model class of content type to create a instance?

You need to create an instance of the class. ct.model_class() returns the class, not an instance of it. Try the following: >>> from django.contrib.contenttypes.models import ContentType >>> ct = ContentType.objects.get(model=”user”) >>> ct_class = ct.model_class() >>> ct_instance = ct_class() >>> ct_instance.username=”hellow” >>> ct_instance.save()

How can I restrict Django’s GenericForeignKey to a list of models?

For example, your apps are app and app2 and there are A, B models in app and there are C, D models in app2. you want to see only app.A and app.B and app2.C from django.db import models class TaggedItem(models.Model): tag = models.SlugField() limit = models.Q(app_label=”app”, model=”a”) | models.Q(app_label=”app”, model=”b”) | models.Q(app_label=”app2″, model=”c”) content_type = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)