How to define a url that does not belong to any app?

2017-11-25 Thread Kubilay Yazoğlu
Hi there. I have only one week of experience in Django, some things aren't 
clear to me yet.

I want to create a page where users can access by clicking on a button in 
homepage.
Since this page contains plain text and there is no functionality in it, it 
does not have be in any of the apps. But since I had to write its view 
function in somewhere, I've written it in the same view file of homepage 
(That's my thought. Correct me if I'm wrong)

First question is, where to define its view function? As I said I've 
defined it in the same view file of homepage. Not sure if that's the right 
way.
Secondly, how to define its url? I tried the following code but it does not 
work. I get this error when I click on the button in homepage: The current 
URL, learnmore.html, didn't match any of these.

url(r'^learnmore/$', learnmore_view)

-- 
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/d6750ede-da18-406a-a1e5-2336827b6ae3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to define a url that does not belong to any app?

2017-11-26 Thread Kubilay Yazoğlu
SOLVED. Looks like I've done a silly mistake. Thanks for your answers 
though.

 Mistake was to write href="learnmore.html" in home page html. I changed 
this to href="{% url 'learnmore' %}, learnmore is the name of the view 
function of learnmore page.

26 Kasım 2017 Pazar 02:00:25 UTC+3 tarihinde Kubilay Yazoğlu yazdı:
>
> Hi there. I have only one week of experience in Django, some things aren't 
> clear to me yet.
>
> I want to create a page where users can access by clicking on a button in 
> homepage.
> Since this page contains plain text and there is no functionality in it, 
> it does not have be in any of the apps. But since I had to write its view 
> function in somewhere, I've written it in the same view file of homepage 
> (That's my thought. Correct me if I'm wrong)
>
> First question is, where to define its view function? As I said I've 
> defined it in the same view file of homepage. Not sure if that's the right 
> way.
> Secondly, how to define its url? I tried the following code but it does 
> not work. I get this error when I click on the button in homepage: The 
> current URL, learnmore.html, didn't match any of these.
>
> url(r'^learnmore/$', learnmore_view)
>
>

-- 
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/5f389587-6330-439a-ac4b-8fab3848df5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to select the proper column when I use ForeignKey?

2017-11-26 Thread Kubilay Yazoğlu
Hello. I have two models. In one of them, I declared a foreign key to the 
other one. Since this is done in Django by only specifying the Class name, 
without specifying the field name(column name), when I try to create an 
object in admin panel, it pulls the wrong column information.

Two models A and B.
B has a Foreignkey for accessing A.
A has two fields Field1 and Field2.
When I try to create an instance of B, in the field of Foreignkey, there is 
a drop down menu but the content is not from the right field of A.

How to specify 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/ad0d40a3-cd7f-4f2f-821d-31cc007657b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to select the proper column when I use ForeignKey?

2017-11-27 Thread Kubilay Yazoğlu
Thanks for your answer. I have one more question. What if there are more 
than one primary keys in that table? I'm talking about the unique_together 
case.

27 Kasım 2017 Pazartesi 08:55:45 UTC+3 tarihinde Matemática A3K yazdı:
>
> What Django shows in that dropdown is the __str__() method of the object, 
> define it to your needs in A :)
>
> On Sun, Nov 26, 2017 at 7:49 PM, Kubilay Yazoğlu  > wrote:
>
>> Hello. I have two models. In one of them, I declared a foreign key to the 
>> other one. Since this is done in Django by only specifying the Class name, 
>> without specifying the field name(column name), when I try to create an 
>> object in admin panel, it pulls the wrong column information.
>>
>> Two models A and B.
>> B has a Foreignkey for accessing A.
>> A has two fields Field1 and Field2.
>> When I try to create an instance of B, in the field of Foreignkey, there 
>> is a drop down menu but the content is not from the right field of A.
>>
>> How to specify 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/ad0d40a3-cd7f-4f2f-821d-31cc007657b1%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/ad0d40a3-cd7f-4f2f-821d-31cc007657b1%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> 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/60af36a5-7fec-46f7-a348-ae4a8784f01b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to select the proper column when I use ForeignKey?

2017-11-27 Thread Kubilay Yazoğlu
Thanks. I was talking about the composite primary keys in my second 
question. I've seen that there is a library for it. So, no problem now. 
Thank you.

27 Kasım 2017 Pazartesi 01:49:15 UTC+3 tarihinde Kubilay Yazoğlu yazdı:
>
> Hello. I have two models. In one of them, I declared a foreign key to the 
> other one. Since this is done in Django by only specifying the Class name, 
> without specifying the field name(column name), when I try to create an 
> object in admin panel, it pulls the wrong column information.
>
> Two models A and B.
> B has a Foreignkey for accessing A.
> A has two fields Field1 and Field2.
> When I try to create an instance of B, in the field of Foreignkey, there 
> is a drop down menu but the content is not from the right field of A.
>
> How to specify 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/6b65ec89-8bd6-4e92-bb01-f539cbae69da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to select the proper column when I use ForeignKey?

2017-11-27 Thread Kubilay Yazoğlu
Thanks. I was talking about the composite primary keys in my second 
question. I've seen that there is a library for it. So, no problem now. 
Thank you.

27 Kasım 2017 Pazartesi 23:31:29 UTC+3 tarihinde Matemática A3K yazdı:
>
>
>
> On Mon, Nov 27, 2017 at 10:50 AM, Kubilay Yazoğlu  > wrote:
>
>> Thanks for your answer. I have one more question. What if there are more 
>> than one primary keys in that table?
>>
>
> By definition, that won't happen, a primary key is unique. If you add a 
> record with the same key Django will raise an IntegrityError.
>  
>
>> I'm talking about the unique_together case.
>>
>
> I don't understand you
>  
>
>>
>> 27 Kasım 2017 Pazartesi 08:55:45 UTC+3 tarihinde Matemática A3K yazdı:
>>>
>>> What Django shows in that dropdown is the __str__() method of the 
>>> object, define it to your needs in A :)
>>>
>>> On Sun, Nov 26, 2017 at 7:49 PM, Kubilay Yazoğlu  
>>> wrote:
>>>
>>>> Hello. I have two models. In one of them, I declared a foreign key to 
>>>> the other one. Since this is done in Django by only specifying the Class 
>>>> name, without specifying the field name(column name), when I try to create 
>>>> an object in admin panel, it pulls the wrong column information.
>>>>
>>>> Two models A and B.
>>>> B has a Foreignkey for accessing A.
>>>> A has two fields Field1 and Field2.
>>>> When I try to create an instance of B, in the field of Foreignkey, 
>>>> there is a drop down menu but the content is not from the right field of A.
>>>>
>>>> How to specify 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/ad0d40a3-cd7f-4f2f-821d-31cc007657b1%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/django-users/ad0d40a3-cd7f-4f2f-821d-31cc007657b1%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> 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/60af36a5-7fec-46f7-a348-ae4a8784f01b%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/60af36a5-7fec-46f7-a348-ae4a8784f01b%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> 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/ff081369-3fca-4c89-a577-35e3c96a8d90%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.


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.


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
>>  
>> <https://groups.google.com/d/msgid/django-users/57db225c-41bf-43d2-b9d8-ffb3174cddc7%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> 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 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 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
>>> <https://groups.google.com/d/msgid/django-users/87731060-75a6-44c6-8d1f-56cba6d22278%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> 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
> <https://groups.google.com/d/msgid/django-users/CA%2BFDnhLFdpf0Z%3DwSgtd3b7HTW_5xru7m963W%2Bo-g653RdX4w3Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> 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-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
>>>>>  
>>>>> <https://groups.google.com/d/msgid/django-users/87731060-75a6-44c6-8d1f-56cba6d22278%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>
>>> -- 
>>> You received this message because

Problem when trying to display field name on admin panel

2017-12-01 Thread Kubilay Yazoğlu
Hello.
It gives error when I click on my app name in admin panel because of the 
"ratings" field. Without it, it loads fine. 
Error: 
KeyError at /admin/photo/photo/

'manager'

Error during template rendering

In template 
C:\Users\Root\Desktop\PhotashBackend\sanal\lib\site-packages\django\contrib\admin\templates\admin\change_list.html,
 error at line *82*

*The mentioned line is this * {% result_list cl %}


My model:

class Photo(models.Model):
photo = models.IntegerField(primary_key=True, verbose_name='Photo id') 
photoItself = ResizedImageField(upload_to='photopool/', 
default='blog/static/manzara.jpg', verbose_name='Photo')
...
...
...
...
ratings = GenericRelation(Rating, related_query_name='photos')



And this is my admin.py:

from django.contrib import admin
from .models import Photo

class PhotoAdmin(admin.ModelAdmin):
list_display = ['photo', 'contest', 'ownername', 'howmany_votes_gotten', 
'ratings']
list_display_links = ['photo']
list_filter = ['contest']
search_fields = ['ownername']

class Meta:
model = Photo


admin.site.register(Photo, PhotoAdmin)


-- 
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/366ad944-6aac-4bc0-9241-a54dc774b034%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Unresolved filter 'crispy'

2017-12-04 Thread Kubilay Yazoğlu
I'm trying to add crispy forms to my project. 
(http://django-crispy-forms.readthedocs.io/en/latest/)

I installed crispy forms by pip install django-crispy-forms

I added this in installed apps:

'crispy_forms',


And this at the end of settings.py:

CRISPY_TEMPLATE_PACK = 'bootstrap3'


And this at the top of my form.html

{% load crispy_forms_tags %}


Still, I'm getting unresolved filter 'crispy' error. What am I missing?

-- 
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/df75fb0d-c1c1-4cad-ae64-60c862a64011%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to send parameter to view?

2017-12-18 Thread Kubilay Yazoğlu
Hello. I have two apps. Posts and Contests.

In templates/contest/detail.html, there is a button that takes you to 
templates/post/create.html

What I want is to send the contest name from detail to create so that the 
post will be added to the right contest. For that, I guess I should do 
something to send contest name from detail.html to create view of 
post/create. Right?
In the following code (post\views.py), the contest name is determined 
randomly. Help me to get the right contest please.

if request.method == 'POST':
items = Contest.objects.all()
random_item = random.choice(items)
form = PostForm(request.POST, request.FILES)

if form.is_valid():
post = form.save(commit = False)
post.contest = random_item
post.ownername = request.user
post.save()
messages.success(request, 'You have succesfully sent a post')
return HttpResponseRedirect(random_item.get_absolute_url())
else:
form = PostForm()

-- 
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/ddc3b1d3-32a3-4457-a36d-5cbbea6255b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Reporting unwanted behaviours

2018-01-17 Thread Kubilay Yazoğlu


Hi. I want to implement a reporting system in which users report a post 
simply by clicking the report button and later on, admins check it whether 
the post is really against the policy of the website. However, when I make 
a research about Django Reporting Systems, the results are not related to 
this. I was not able to express myself clearly.

So, is there any package I can use? Any tutorials I can follow? Anything 
about this?

-- 
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/3f988b99-140b-4808-a1af-9b2cb2c2242b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.