I have this model:
class Auth(models.Model):
TYPES = (
('agent', 'Agent'),
('broker', 'Broker'),
)
user = models.ForeignKey(User, unique=True)
type = models.CharField(max_length=20, choices=TYPES)
applied = models.BooleanField()
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField(db_index=True)
content_object=generic.GenericForeignKey('content_type', 'object_id')
and whenever I do something like this:
User.objects.create_user(username="myuser", password="myuser", email="myemail.com")
u = User.objects.get(username="myuser")
profile = Auth(user=u)
profile.save()
of course I will receive the error:
IntegrityError: (1048, "Column 'content_type_id' cannot be null")
For my purposes, I can’t avoid contenttypes because Auth is a class where a Broker and Agent class inherits from, which allows me to do multiple custom profiles.
I was wondering if there was a way in which the content type would not be required.
Thanks in advance!
null=Truemakes it optional in the data model,blank=Truemakes it optional when using admin form (otherwise you’ll get validation error).