Re: NOT NULL constraint failed when trying to create form with initial values

2017-11-28 Thread Matemática A3K
On Tue, Nov 28, 2017 at 6:18 PM, Kubilay Yazoğlu wrote: > That did the trick. There were some minor errors after it, but now there > isn't. By the way, I tried this solution before I tried the "initial" > solution but it didn't work at that time. Many thanks. > :) I'm glad you solved it. > > 2

Re: NOT NULL constraint failed when trying to create form with initial values

2017-11-28 Thread Kubilay Yazoğlu
That did the trick. There were some minor errors after it, but now there isn't. By the way, I tried this solution before I tried the "initial" solution but it didn't work at that time. Many thanks. 28 Kasım 2017 Salı 02:49:13 UTC+3 tarihinde Matemática A3K yazdı: > > > > On Mon, Nov 27, 2017 at

Re: NOT NULL constraint failed when trying to create form with initial values

2017-11-27 Thread Matemática A3K
On Mon, Nov 27, 2017 at 7:58 PM, Kubilay Yazoğlu . wrote: > Oh, that's a life saver information. Thanks. I edited my code. > Unfortunately, only thing that has changed is the name of the error which > looks like this right now: NOT NULL constraint failed: > photo_photo.contest_id > > I'm going to

Re: NOT NULL constraint failed when trying to create form with initial values

2017-11-27 Thread Kubilay Yazoğlu .
Oh, that's a life saver information. Thanks. I edited my code. Unfortunately, only thing that has changed is the name of the error which looks like this right now: NOT NULL constraint failed: photo_photo.contest_id I'm going to take a break and try to solve the problem tomorrow. I appreciate your

Re: NOT NULL constraint failed when trying to create form with initial values

2017-11-27 Thread Matemática A3K
On Mon, Nov 27, 2017 at 7:30 PM, Matemática A3K wrote: > > > On Mon, Nov 27, 2017 at 7:18 PM, Kubilay Yazoğlu > wrote: > >> Nice try but I'm still getting this error: IntegrityError at >> /photo/create/ >> >> NOT NULL constraint failed: photo_photo.contest_id_id >> >> >> I tried with both 'conte

Re: NOT NULL constraint failed when trying to create form with initial values

2017-11-27 Thread Matemática A3K
On Mon, Nov 27, 2017 at 7:18 PM, Kubilay Yazoğlu wrote: > Nice try but I'm still getting this error: IntegrityError at > /photo/create/ > > NOT NULL constraint failed: photo_photo.contest_id_id > > > I tried with both 'contest': random_item and 'contest_id': > random_item.contest_id. (I don't k

Re: NOT NULL constraint failed when trying to create form with initial values

2017-11-27 Thread Kubilay Yazoğlu
Nice try but I'm still getting this error: IntegrityError at /photo/create/ NOT NULL constraint failed: photo_photo.contest_id_id I tried with both 'contest': random_item and 'contest_id': random_item.contest_id. (I don't know why you wrote contest instead of contest_id. Field name is contest

Re: NOT NULL constraint failed when trying to create form with initial values

2017-11-27 Thread Matemática A3K
> items = Contest.objects.all() > random_item = random.choice(items) > > if request.method =='POST': > data = {'contest': random_item, > 'ownername': 'SUMMERSON', > } > form=PhotoForm(request.POST, initial=data) > if form.is_valid(): > photo = form.save()

Re: NOT NULL constraint failed when trying to create form with initial values

2017-11-27 Thread Kubilay Yazoğlu
Yes, photo_id is PK. So I shouldn't even give its value to the form in initial values I guess? Contest_id isn't PK, I want to select a random contest id from contest objects. (I decided to do this just now, my former code does not include this :) ) By the way, contest_id is foreign key in Phot

Re: NOT NULL constraint failed when trying to create form with initial values

2017-11-27 Thread Matemática A3K
You shouldn't give the PK of new objects, leave that to Django. If photo_id is the PK of Photo, don't set it, Django will on save. If the same goes for Contest, then do a "contest = Contest()" - create a new contest - and assign it to the photo "photo.contest = contest", then "photo.save" On Mon,

NOT NULL constraint failed when trying to create form with initial values

2017-11-27 Thread Kubilay Yazoğlu
Hi. I'm trying to create a form to construct an object for my Photo class. All of the objects fields except the photo itself will be invisible to the user. So, the only thing can be seen in the form is the button to select and upload the photo. There is no problem with creating the form page. T

NOT NULL constraint failed when trying to create form with initial values

2017-11-27 Thread Kubilay Yazoğlu
Hi. I'm trying to create a form to construct an object for my Photo class. All of the objects fields except the photo itself will be invisible to the user. So, the only thing can be seen in the form is the button to select and upload the photo. There is no problem with creating the form page. T