from django.contrib.auth.models import AbstractUser
class CustomUserProfile(AbstractUser):
'''When I was defining the custom user model for the first time I had to migrate things in
a very specific order for them to work. I had to migrate the main app first (the one with this model)
then the sites app and then the main again and then everything else.'''
topic = models.ManyToManyField(MyModel, through='Info')
class Info(models.Model):
user = models.ForeignKey(CustomUserProfile, on_delete=models.CASCADE)
topic = models.ForeignKey(MyModel, on_delete=models.CASCADE)
level = models.IntegerField()from topic.models import *
user = CustomUserProfile()
user.save()Running those commands in the shell does not execute the model-level validation you are expecting (checking for non-blank username and uniqueness in this case). You'll need to run that yourself when working directly with your user objects in the shell.
https://docs.djangoproject.com/en/1.9/ref/models/instances/#validating-objects
The database integrity checks still apply though. If you try to create a second user with an empty username, you should receive an IntegrityError upon running user.save().
-Jamez