models.py
TITLE = (
(\'Classroom\', \'Classroom\'),
(\'Playground\', \'Playground\'),
(\'Staff Room\',\'Staff Room\'),
)
class Location(models.M
When you create the user or superuser the model instance is created but it does not have corresponding location
row. Hence, accessing instance.location.is_active
gives you the error.
You can update the signal handler to create the location
instance first and then set appropriate attributes. As below:
def location_title(sender, instance, created, **kwargs):
#also check for created flag
if created and instance.is_superuser:
location = Location(user=instance)
location.is_active=True
location.save()
post_save.connect(location_title, sender=User)
If you want to choices for title
field you can define that in field. Your definition of the title
field is not correct, change it to
title = models.CharField('Incident Type', max_length=200, choices=TITLE,
default='Classroom')
You are incorrectly using detfault=TITLE
instead of choices=TITLE
.