The problem is when a user submit a picture I get this error. I think I understand why I get this error because the board dropbox is not validating even though I select a Board.
IntegrityError at /picture/
pet_picture.board_id may not be NULLRequest Method: POST
Request URL:
Django Version: 1.4.3
Exception Type: IntegrityError
Exception Value: pet_picture.board_id may not be NULL
Traceback:
File "C:\o\mysite\pet\views.py" in PictureCreator
106. picture = Picture.objects.create(user=request.user)
I think The problem is at my PictureCreator function at views.py
def PictureCreator(request):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('pet.views.LoginRequest'))
if request.method == "POST":
form = PictureForm(request.POST , request.FILES)
if form.is_valid():
picture = Picture.objects.create(user=request.user)
picture.image = form.cleaned_data['image']
picture.description = form.cleaned_data['description']
picture.board = form.cleaned_data['board']
picture.save()
return render(request,'picture.html',{'form':PictureForm()})
I think the problem At this particular statement It does not valid my board dropbox . How can I make it valid? picture.board = form.cleaned_data['board']
My parts of my forms.py
class PictureForm(forms.ModelForm):
board = forms.ModelChoiceField(queryset=Board.objects.all())
class Meta:
model = Picture
fields = ('image','description','board',)
My models.py
from django.db import models
from django.db.models.signals import post_save
from django.contrib.auth.models import User
class Person(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=100)
image = models.FileField(upload_to="images/",blank=True,null=True)
def __unicode__(self):
return self.name
class Picture(models.Model):
user = models.ForeignKey(User)
board = models.ForeignKey(Board)
image = models.FileField(upload_to="images/",blank=True,null=True)
description = models.TextField()
def __unicode__(self):
return self.description
How can I fix this? Thank you for helping me :D