Guest User

Untitled

a guest
Jul 18th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. user = models.OneToOneField(User, on_delete=models.CASCADE)
  2.  
  3. join_date = models.DateField(default=datetime.today())
  4.  
  5. end_date = models.DateField(default=datetime.today() + timedelta(days=7))
  6.  
  7. package_status = models.BooleanField(default=True,blank=True)
  8.  
  9. phone_number = models.CharField(max_length=30, blank=True)
  10.  
  11.  
  12. idboard= models.CharField(max_length=30, blank=True)
  13.  
  14. if created:
  15. Profile.objects.create(user=instance)
  16. instance.profile.save()
  17.  
  18. email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')
  19.  
  20. phone_number = forms.CharField(help_text='Required. Format: 03001234567')
  21.  
  22. idboard = forms.ModelChoiceField(queryset=Board_TB.objects.filter(pk__in=b[1,2]),required=False)
  23.  
  24. class Meta:
  25.  
  26. model = User
  27.  
  28. fields = ('username', 'email','password1', 'password2','phone_number','idboard')
  29.  
  30. if request.method == 'POST':
  31.  
  32. form = SignUpForm(request.POST)
  33.  
  34. if form.is_valid():
  35.  
  36. user = form.save()
  37.  
  38. user.refresh_from_db() # load the profile instance created by the
  39. signal
  40.  
  41. user.profile.phone_number = form.cleaned_data.get('phone_number')
  42. user.profile.idboard = form.cleaned_data.get('idboard')
  43. user.save()
  44.  
  45. raw_password = form.cleaned_data.get('password1')
  46.  
  47. user = authenticate(username=user.username, password=raw_password)
  48. login(request, user)
  49.  
  50. return redirect('index')
  51.  
  52. else:
  53.  
  54. form = SignUpForm()
  55.  
  56. return render(request, 'accounts/signup.html',{'form' : form,})
  57.  
  58. but I am facing this error:
  59. IntegrityError at /accounts/signup/
  60. ('23000', "[23000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot insert the value NULL into column 'idboard', table 'edxlinkdb.dbo.accounts_profile'; column does not allow nulls. UPDATE fails. (515) (SQLExecDirectW); [23000] [Microsoft][SQL Server Native Client 11.0][SQL Server]The statement has been terminated. (3621)")
Add Comment
Please, Sign In to add comment