I’m getting this error in my form with no context telling me to correct the errors below. I tried doing several things such as adding blank=True
to every optional field that I could insert it into, logging which I found to be ineffective while using native Django forms, and I even tried commenting out various parts of my add_fieldset
variable in the UserAdmin
class.
class UserAdmin(BaseUserAdmin):
"""Define the admin pages for users"""
order = ['id']
ordering = ('email',)
list_display = ['email', 'first_name', 'last_name']
fieldsets = (
(None, {'fields': ('email',
'password',
'first_name',
'last_name',
'gender',
'birthday',
'verified_male',
'verified_female_1',
'verified_female_2'
)}),
(
_('Permissions'),
{
'fields': (
'is_active',
'is_staff',
'is_superuser',
'verified',
'vetted',
)
}
),
(_('Important dates'), {'fields': ['last_login']}),
)
readonly_fields = ['last_login', 'age']
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': (
'email',
'password',
'first_name',
'last_name',
'gender',
'birthday',
)}),
(
_('Permissions'),
{
'fields': (
'is_active',
'is_staff',
'is_superuser',
'verified',
'vetted',
)
}
)
)
admin.site.register(models.User, UserAdmin)
Here is my models.py:
class UserManager(BaseUserManager):
def create_user(self, email, password=None, **extra_fields):
"""Create, save, and return a new user"""
if not email:
raise ValueError('User have must have an email address')
user = self.model(email=self.normalize_email(email), **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, password, first_name, last_name, gender, birthday, **extra_fields):
"""Create and return a new superuser"""
verified = True
vetted = True
user = self.create_user(email, password, verified=verified, vetted=vetted, first_name=first_name, last_name=last_name, gender=gender, birthday=birthday, **extra_fields)
user.is_staff = True
user.is_superuser = True
user.save(using=self._db)
return user
class User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=255, unique=True)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
USERNAME_FIELD = 'email'
# verification info
verified = models.BooleanField()
vetted = models.BooleanField()
verified_male = models.ForeignKey('self', null=True, on_delete=models.SET_NULL, related_name="male", blank=True)
verified_female_1 = models.ForeignKey('self', null=True, on_delete=models.SET_NULL, related_name="female1", blank=True)
verified_female_2 = models.ForeignKey('self', null=True, on_delete=models.SET_NULL, related_name="female2", blank=True)
# basic information
first_name = models.CharField(max_length=16)
last_name = models.CharField(max_length=16)
gender = models.CharField(max_length=1) # Male = M, Female = F
birthday = models.DateField()
@property
def age(self):
return (datetime.date.today() - self.birthday).days // 365 # Calculated from birthday
# profile starts here
bio = models.CharField(max_length=128, null=True, blank=True)
photos = ArrayField(models.ImageField(upload_to='images'), size=8, null=True, blank=True)
prompts = ArrayField(models.TextField(), size=4, null=True, blank=True)
# more info
height = models.SmallIntegerField(null=True, blank=True) # height in inches
objects = UserManager()
class SeekingChoice(Enum):
MEN = "Men"
WOMEN = "Women"
BOTH = "Both men and women"
seeking = [(tag, tag.value) for tag in SeekingChoice]
class EthnicityChoice(Enum):
WHITE = "White/Caucasian"
BLACK = "Black/African"
LATINO = "Hispanic/Latino"
EAST_ASIAN = "East Asian/Pacific Islander"
MIDDLE_EAST = "Middle Eastern/Indian"
OTHER = "Other"
ethnicity = [(tag, tag.value) for tag in EthnicityChoice]
class ChildrenStatusChoice(Enum):
DOESNTHAVE_DOESNTWANT = "Doesn't have/doesn't want"
DOESNTHAVE_WANTS = "Doesn't have/wants"
HAS_DOESNTWANTMORE = "Has/doesn't want more"
HAS_WANTSMORE = "Has/wants more"
children_status = [(tag, tag.value) for tag in ChildrenStatusChoice]
class ReligionChoice(Enum):
PROTESTANT = "Christian/Protestant"
CATHOLIC = "Christian/Catholic"
JEWISH = "Jewish"
MUSLIM = "Muslim"
BUDDHIST = "Buddhist"
HINDI = "Hindi"
AGNOSTIC = "Agnostic"
ATHEIST = "Atheist"
OTHER = "Other"
religion = [(tag, tag.value) for tag in ReligionChoice]
class PoliticsChoice(Enum):
MARXIST = "Marxist"
LIBERAL = "Liberal"
LIBERTARIAN = "Libertarian"
CENTRIST = "Centrist"
CONSERVATIVE = "Conservative"
APOLITICAL = "Apolitical"
OTHER = "Other"
politics = [(tag, tag.value) for tag in PoliticsChoice]
class PetsChoice(Enum):
DOG = "Dog"
CAT = "Cat"
OTHER = "Other"
pets = [(tag, tag.value) for tag in PetsChoice]
class AlcoholChoice(Enum):
NO = "No"
SOMETIMES = "Sometimes"
YES = "Yes"
alcohol = [(tag, tag.value) for tag in AlcoholChoice]
class SmokingChoice(Enum):
NO = "No"
SOCIALLY = "Socially"
REGUARLY = "Regularly"
smoking = [(tag, tag.value) for tag in SmokingChoice]
class MarijuanaChoice(Enum):
NO = "No"
SOCIALLY = "Socially"
REGULARLY = "Regularly"
marijuana = [(tag, tag.value) for tag in MarijuanaChoice]
class EducationLevelChoice(Enum):
DID_NOT_GRADUATE = "Did not graduate high school"
DIPLOMA = "Diploma/GED"
UNDERGRAD = "Undergrad"
POSTGRAD = "Postgrad"
education_level = [(tag, tag.value) for tag in EducationLevelChoice]