Django User Profile Inline Creation Integrity Error on Save -
Django User Profile Inline Creation Integrity Error on Save -
i'm having issues user profiles in django currently.
i followed recommendations , created user profile:
class userprofile(models.model): user = models.onetoonefield(user) is_teacher = models.booleanfield(verbose_name = "teacher", help_text = "designates whether user teacher , can administer , add together students , classes") school = models.foreignkey(school) def __unicode__(self): homecoming self.user.username def save(self, *args, **kwargs): if not self.pk: try: p = userprofile.objects.get(user=self.user) self.pk = p.pk except userprofile.doesnotexist: pass super(userprofile, self).save(*args, **kwargs)
i inlined user profile user admin page. utilize create sure user profile created along user:
def create_user_profile(sender, instance, created, **kwargs): """create userprofile when new user saved""" if created: print "user profile creation: ", created userprofile.objects.get_or_create(user=instance)
the issue arises when go add together new user. before adding school field, able fill in , work great. after adding school field, integrityerror states userprofile.school_id cannot null. going wrong here?
i believe issue selection of school not beingness passed get_or_create , when goes create userprofile, sees nothing. how did work before, when clicking checkbox is_teacher? also, how go fixing this?
yes, selection of school isn't getting passed, it's not getting passed here:
userprofile.objects.get_or_create(user=instance)
you're setting user, , trying create profile.
add null=true, blank=true
school field, or figure out school selection was, , pass in:
userprofile.objects.get_or_create(user=instance, school=school)
django django-admin django-authentication
Comments
Post a Comment