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.


>
> 28 Kasım 2017 Salı 02:49:13 UTC+3 tarihinde Matemática A3K yazdı:
>>
>>
>>
>> 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 take a break and try to solve the problem tomorrow. I
>>> appreciate your help.
>>>
>>
>> Alright, for tomorrow then:
>>
>> I don't usually use "initial" but if you are excluding (or not including)
>> the field in the form, "initial" would not be useful. A workaround would be:
>>
>>
>> if form.is_valid():
>> photo = form.save(commit=False)
>>
>> photo.contest = random_item
>>
>> photo.owner = 'SUMMERSON'
>>
>> photo.save()
>>
>>
>>
>>>
>>> On Tue, Nov 28, 2017 at 1:32 AM, Matemática A3K 
>>> wrote:
>>>


 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 '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_id)
>>
>> That's because what you are passing is empty and the field is
> required. Are you sure that you have Contest objects?
>
> There is a convention in Django (models and ORM), "object.foreign_key"
> gives you the object, while "object.foreign_key_id" gives you the id of
> that object (and is what it is stored in the database). You should name
> your field only "contest" for avoiding confusions.
>

 Try "contest_id": random_object



>
>
>
>>
>> 28 Kasım 2017 Salı 01:03:50 UTC+3 tarihinde Matemática A3K yazdı:
>>
>>>
>>> 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()  # Instances go in lowercase, otherwise 
 you are doing it to the class
 else:
 form = PhotoForm()

 --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/87731060-75a6
>> -44c6-8d1f-56cba6d22278%40googlegroups.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
 --
 You received this message because you are subscribed to a topic in the
 Google Groups "Django users" group.
 To unsubscribe from this topic, visit https://groups.google.com/d/to
 pic/django-users/EUOXhT4V9Is/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 django-users...@googlegroups.com.
 To post to this group, send email to django...@googlegroups.com.
 Visit this group at https://groups.google.com/group/django-users.
 To view this discussion on the web visit https://groups.google.com/d/ms
 gid/django-users/CA%2BFDnhLFdpf0Z%3DwSgtd3b7HTW_5xru7m963W%
 2Bo-g653RdX4w3Q%40mail.gmail.com
 
 .

 For more options, visit https://groups.google.com/d/optout.

>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.

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 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 take a break and try to solve the problem tomorrow. I 
>> appreciate your help.
>>
>
> Alright, for tomorrow then:
>
> I don't usually use "initial" but if you are excluding (or not including) 
> the field in the form, "initial" would not be useful. A workaround would be:
>
>
> if form.is_valid():
> photo = form.save(commit=False)
>
> photo.contest = random_item
>
> photo.owner = 'SUMMERSON'
>
> photo.save()
>
>  
>
>>
>> On Tue, Nov 28, 2017 at 1:32 AM, Matemática A3K > > wrote:
>>
>>>
>>>
>>> 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 '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_id)
>
> That's because what you are passing is empty and the field is 
 required. Are you sure that you have Contest objects?

 There is a convention in Django (models and ORM), "object.foreign_key" 
 gives you the object, while "object.foreign_key_id" gives you the id of 
 that object (and is what it is stored in the database). You should name 
 your field only "contest" for avoiding confusions.

>>>
>>> Try "contest_id": random_object
>>>
>>>  
>>>

  

>
> 28 Kasım 2017 Salı 01:03:50 UTC+3 tarihinde Matemática A3K yazdı:
>
>>
>> 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()  # Instances go in lowercase, otherwise you 
>>> are doing it to the class
>>> else:
>>> form = PhotoForm()
>>>
>>> -- 
> You received this message because you are subscribed to the Google 
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send 
> an email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/87731060-75a6-44c6-8d1f-56cba6d22278%40googlegroups.com
>  
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>


>>> -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/django-users/EUOXhT4V9Is/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> django-users...@googlegroups.com .
>>> To post to this group, send email to django...@googlegroups.com 
>>> .
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CA%2BFDnhLFdpf0Z%3DwSgtd3b7HTW_5xru7m963W%2Bo-g653RdX4w3Q%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CALz%3DsVGYzWbk0%3DzoyMDa_3MB3co7CNiez00aX4kSfFOiyN2Mmw%40mail.gmail.com
>>  
>> 

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 take a break and try to solve the problem tomorrow. I
> appreciate your help.
>

Alright, for tomorrow then:

I don't usually use "initial" but if you are excluding (or not including)
the field in the form, "initial" would not be useful. A workaround would be:


if form.is_valid():
photo = form.save(commit=False)

photo.contest = random_item

photo.owner = 'SUMMERSON'

photo.save()



>
> On Tue, Nov 28, 2017 at 1:32 AM, Matemática A3K 
> wrote:
>
>>
>>
>> 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 '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_id)

 That's because what you are passing is empty and the field is required.
>>> Are you sure that you have Contest objects?
>>>
>>> There is a convention in Django (models and ORM), "object.foreign_key"
>>> gives you the object, while "object.foreign_key_id" gives you the id of
>>> that object (and is what it is stored in the database). You should name
>>> your field only "contest" for avoiding confusions.
>>>
>>
>> Try "contest_id": random_object
>>
>>
>>
>>>
>>>
>>>

 28 Kasım 2017 Salı 01:03:50 UTC+3 tarihinde Matemática A3K yazdı:

>
> 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()  # Instances go in lowercase, otherwise you 
>> are doing it to the class
>> else:
>> form = PhotoForm()
>>
>> --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users+unsubscr...@googlegroups.com.
 To post to this group, send email to django-users@googlegroups.com.
 Visit this group at https://groups.google.com/group/django-users.
 To view this discussion on the web visit https://groups.google.com/d/ms
 gid/django-users/87731060-75a6-44c6-8d1f-56cba6d22278%40goog
 legroups.com
 
 .

 For more options, visit https://groups.google.com/d/optout.

>>>
>>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>> pic/django-users/EUOXhT4V9Is/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CA%2BFDnhLFdpf0Z%3DwSgtd3b7HTW_5xru7m963W%
>> 2Bo-g653RdX4w3Q%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CALz%3DsVGYzWbk0%3DzoyMDa_
> 3MB3co7CNiez00aX4kSfFOiyN2Mmw%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubsc

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 help.

On Tue, Nov 28, 2017 at 1:32 AM, Matemática A3K 
wrote:

>
>
> 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 '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_id)
>>>
>>> That's because what you are passing is empty and the field is required.
>> Are you sure that you have Contest objects?
>>
>> There is a convention in Django (models and ORM), "object.foreign_key"
>> gives you the object, while "object.foreign_key_id" gives you the id of
>> that object (and is what it is stored in the database). You should name
>> your field only "contest" for avoiding confusions.
>>
>
> Try "contest_id": random_object
>
>
>
>>
>>
>>
>>>
>>> 28 Kasım 2017 Salı 01:03:50 UTC+3 tarihinde Matemática A3K yazdı:
>>>

 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()  # Instances go in lowercase, otherwise you 
> are doing it to the class
> else:
> form = PhotoForm()
>
> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/87731060-75a6-44c6-8d1f-56cba6d22278%40googlegroups.com
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/EUOXhT4V9Is/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CA%2BFDnhLFdpf0Z%3DwSgtd3b7HTW_
> 5xru7m963W%2Bo-g653RdX4w3Q%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALz%3DsVGYzWbk0%3DzoyMDa_3MB3co7CNiez00aX4kSfFOiyN2Mmw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


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 '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_id)
>>
>> That's because what you are passing is empty and the field is required.
> Are you sure that you have Contest objects?
>
> There is a convention in Django (models and ORM), "object.foreign_key"
> gives you the object, while "object.foreign_key_id" gives you the id of
> that object (and is what it is stored in the database). You should name
> your field only "contest" for avoiding confusions.
>

Try "contest_id": random_object



>
>
>
>>
>> 28 Kasım 2017 Salı 01:03:50 UTC+3 tarihinde Matemática A3K yazdı:
>>
>>>
>>> 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()  # Instances go in lowercase, otherwise you 
 are doing it to the class
 else:
 form = PhotoForm()

 --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/87731060-75a6-44c6-8d1f-56cba6d22278%40googlegroups.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BFDnhLFdpf0Z%3DwSgtd3b7HTW_5xru7m963W%2Bo-g653RdX4w3Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


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 know why you wrote contest instead of 
> contest_id. Field name is contest_id)
>
> That's because what you are passing is empty and the field is required.
Are you sure that you have Contest objects?

There is a convention in Django (models and ORM), "object.foreign_key"
gives you the object, while "object.foreign_key_id" gives you the id of
that object (and is what it is stored in the database). You should name
your field only "contest" for avoiding confusions.



>
> 28 Kasım 2017 Salı 01:03:50 UTC+3 tarihinde Matemática A3K yazdı:
>
>>
>> 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()  # Instances go in lowercase, otherwise you are 
>>> doing it to the class
>>> else:
>>> form = PhotoForm()
>>>
>>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/87731060-75a6-44c6-8d1f-56cba6d22278%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BFDnhK%3Dkkjra0nXZ380%3D667xT0JwD8a2rmaPy0g%3DXEPU9Rx9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


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_id)


28 Kasım 2017 Salı 01:03:50 UTC+3 tarihinde Matemática A3K yazdı:
>
>
> 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()  # Instances go in lowercase, otherwise you are 
>> doing it to the class
>> else:
>> form = PhotoForm()
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87731060-75a6-44c6-8d1f-56cba6d22278%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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()  # Instances go in lowercase, otherwise you are 
> doing it to the class
> else:
> form = PhotoForm()
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BFDnhLDx6Dih_N%3DLWBZPJiumNYvWAmm6Qt4psUTpCrYP1ykUA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


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 Photo. It is a PK in Contest. What 
am I doing wrong now? It gives the exact same error.

items = Contest.objects.all()
random_item = random.choice(items)

if request.method =='POST':
data = {'contest_id': random_item.contest_id,
'ownername': 'SUMMERSON',
}
form=PhotoForm(request.POST, initial=data)
if form.is_valid():
Photo = form.save()
else:
form = PhotoForm()




28 Kasım 2017 Salı 00:04:25 UTC+3 tarihinde Matemática A3K yazdı:
>
> 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, Nov 27, 2017 at 5:56 PM, Kubilay Yazoğlu  > wrote:
>
>> 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. The problem is, giving 
>> the initial values for the rest of the fields. 
>> This is the relevant code in my view file:
>>
>>   
>>
>> if request.method =='POST':
>> data = {'photo_id': get_latest_photo_id_plusone(),
>> 'contest_id': get_latest_contest_id_plusone(),
>> 'ownername': 'SUMMERSON',
>> }
>> form=PhotoForm(request.POST, initial=data)
>> if form.is_valid():
>> Photo = form.save()
>> else:
>> form = PhotoForm()
>>
>>
>> And the relevant functions:
>>
>>   
>>
>> def get_latest_photo_id_plusone():
>> max_rating = 
>> Photo.objects.all().aggregate(Max('photo_id'))['photo_id__max']
>> return max_rating+1
>>
>>
>> def get_latest_contest_id_plusone():
>> max_rating 
>> =Photo.objects.all().aggregate(Max('contest_id'))['contest_id__max']
>> return max_rating+1
>>
>>
>>
>> The error arises when I click on the send button after I select the 
>> image. It says: 
>>
>> IntegrityError at /photo/create/
>> NOT NULL constraint failed: photo_photo.contest_id_id
>>
>> But I've given the contest_id value. Haven't I? Where is the problem and 
>> how can I fix it?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/57db225c-41bf-43d2-b9d8-ffb3174cddc7%40googlegroups.com
>>  
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/abb4fb48-2c9f-4453-823a-c9def3053b59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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, Nov 27, 2017 at 5:56 PM, Kubilay Yazoğlu 
wrote:

> 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. The problem is, giving
> the initial values for the rest of the fields.
> This is the relevant code in my view file:
>
>
>
> if request.method =='POST':
> data = {'photo_id': get_latest_photo_id_plusone(),
> 'contest_id': get_latest_contest_id_plusone(),
> 'ownername': 'SUMMERSON',
> }
> form=PhotoForm(request.POST, initial=data)
> if form.is_valid():
> Photo = form.save()
> else:
> form = PhotoForm()
>
>
> And the relevant functions:
>
>
>
> def get_latest_photo_id_plusone():
> max_rating = 
> Photo.objects.all().aggregate(Max('photo_id'))['photo_id__max']
> return max_rating+1
>
>
> def get_latest_contest_id_plusone():
> max_rating 
> =Photo.objects.all().aggregate(Max('contest_id'))['contest_id__max']
> return max_rating+1
>
>
>
> The error arises when I click on the send button after I select the image.
> It says:
>
> IntegrityError at /photo/create/
> NOT NULL constraint failed: photo_photo.contest_id_id
>
> But I've given the contest_id value. Haven't I? Where is the problem and
> how can I fix it?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/57db225c-41bf-43d2-b9d8-ffb3174cddc7%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BFDnhJM1k8kk4ZudQsaH9QpsnAAHHHDbMYwLB09oTT0L2bfNg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


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. The problem is, giving the 
initial values for the rest of the fields. 
This is the relevant code in my view file:

  

if request.method =='POST':
data = {'photo_id': get_latest_photo_id_plusone(),
'contest_id': get_latest_contest_id_plusone(),
'ownername': 'SUMMERSON',
}
form=PhotoForm(request.POST, initial=data)
if form.is_valid():
Photo = form.save()
else:
form = PhotoForm()


And the relevant functions:

  

def get_latest_photo_id_plusone():
max_rating = 
Photo.objects.all().aggregate(Max('photo_id'))['photo_id__max']
return max_rating+1


def get_latest_contest_id_plusone():
max_rating 
=Photo.objects.all().aggregate(Max('contest_id'))['contest_id__max']
return max_rating+1



The error arises when I click on the send button after I select the image. 
It says: 

IntegrityError at /photo/create/
NOT NULL constraint failed: photo_photo.contest_id_id

But I've given the contest_id value. Haven't I? Where is the problem and 
how can I fix it?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/57db225c-41bf-43d2-b9d8-ffb3174cddc7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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. The problem is, giving the 
initial values for the rest of the fields. 
This is the relevant code in my view file:

if request.method =='POST':
data = {'photo_id': get_latest_photo_id_plusone(),
'contest_id': get_latest_contest_id_plusone(),
'ownername': 'SUMMERSON',
}
form=PhotoForm(request.POST, initial=data)
if form.is_valid():
Photo = form.save()
else:
form = PhotoForm()

And the relevant functions:

def get_latest_photo_id_plusone():
max_rating = 
Photo.objects.all().aggregate(Max('photo_id'))['photo_id__max']
return max_rating+1


def get_latest_contest_id_plusone():
max_rating 
=Photo.objects.all().aggregate(Max('contest_id'))['contest_id__max']
return max_rating+1

The error arises when I click on the send button after I select the image. 
It says: 

IntegrityError at /photo/create/
NOT NULL constraint failed: photo_photo.contest_id_id

But I've given the contest_id value. Haven't I? Where is the problem and 
how can I fix it?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ad42fcc2-7c20-48c0-9770-f2408c14a4e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.