Re: Django 1.9.8 with mysql 'Commands out of sync; you can't run this command now' exception

2018-09-23 Thread mottaz hejaze
try

latest_message = Message.objects.filter(example_field=1)[::-1].first()


On Mon, Sep 24, 2018 at 5:55 AM  wrote:

> I am a python developer and I am using Django 1.9.8 for my project.
> I am having a problem with MySQL like below:
>
> I have a model named 'Message' and sometimes when running this code, I got
> the exception 'Commands out of sync; you can't run this command now'
>
> latest_message = 
> Message.objects.order_by("-id").filter(example_field=1).first()
>
> can you point out to me why does it happen and how to fix it?
> thanks,
> Thanh Tran
>
> --
> 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/740fac2d-3399-45d3-bd96-54a76e7f2335%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/CAHV4E-ch5LVk%2BkFTFw12A5Bnkah7ALc2r97Y8G_imHjXcikAsg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.9.8 with mysql 'Commands out of sync; you can't run this command now' exception

2018-09-23 Thread Adolfo Cueto
i know it, that problem ocurred when mysql is being used by other
process... so you can add  CONN_MAX_AGE: 0 in your conection string... and
also try to use a diferent database and avoid to use multi threading
processes

El dom., 23 sept. 2018 a las 23:41,  escribió:

> Thank you so much Adolfo. I know your code is the best practice but are
> you sure your code will solve the problem?
>
> On Monday, September 24, 2018 at 11:13:14 AM UTC+7, Adolfo Cueto wrote:
>>
>> Hey man try to change you code line like this
>>
>> latest_message = 
>> Message.objects.filter(example_field=1).order_by("-id").first()
>>
>>
>> El dom., 23 sept. 2018 a las 22:55,  escribió:
>>
>>> I am a python developer and I am using Django 1.9.8 for my project.
>>> I am having a problem with MySQL like below:
>>>
>>> I have a model named 'Message' and sometimes when running this code, I
>>> got the exception 'Commands out of sync; you can't run this command now'
>>>
>>> latest_message = 
>>> Message.objects.order_by("-id").filter(example_field=1).first()
>>>
>>> can you point out to me why does it happen and how to fix it?
>>> thanks,
>>> Thanh Tran
>>>
>>> --
>>> 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/740fac2d-3399-45d3-bd96-54a76e7f2335%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/eea6b14a-e6d7-4777-a214-a51b86b89431%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%2Bb6%2BDD1G%2B8vwE%2B86kYB74VHVergeqybGZR4%3DYNZ7tMaWdxuFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.9.8 with mysql 'Commands out of sync; you can't run this command now' exception

2018-09-23 Thread thanh
Thank you so much Adolfo. I know your code is the best practice but are you 
sure your code will solve the problem?

On Monday, September 24, 2018 at 11:13:14 AM UTC+7, Adolfo Cueto wrote:
>
> Hey man try to change you code line like this
>
> latest_message = 
> Message.objects.filter(example_field=1).order_by("-id").first()
>
>
> El dom., 23 sept. 2018 a las 22:55, > 
> escribió:
>
>> I am a python developer and I am using Django 1.9.8 for my project.
>> I am having a problem with MySQL like below:
>>
>> I have a model named 'Message' and sometimes when running this code, I 
>> got the exception 'Commands out of sync; you can't run this command now'
>>
>> latest_message = 
>> Message.objects.order_by("-id").filter(example_field=1).first()
>>
>> can you point out to me why does it happen and how to fix it?
>> thanks,
>> Thanh Tran
>>
>> -- 
>> 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/740fac2d-3399-45d3-bd96-54a76e7f2335%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/eea6b14a-e6d7-4777-a214-a51b86b89431%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.9.8 with mysql 'Commands out of sync; you can't run this command now' exception

2018-09-23 Thread Adolfo Cueto
Hey man try to change you code line like this

latest_message = Message.objects.filter(example_field=1).order_by("-id").first()


El dom., 23 sept. 2018 a las 22:55,  escribió:

> I am a python developer and I am using Django 1.9.8 for my project.
> I am having a problem with MySQL like below:
>
> I have a model named 'Message' and sometimes when running this code, I got
> the exception 'Commands out of sync; you can't run this command now'
>
> latest_message = 
> Message.objects.order_by("-id").filter(example_field=1).first()
>
> can you point out to me why does it happen and how to fix it?
> thanks,
> Thanh Tran
>
> --
> 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/740fac2d-3399-45d3-bd96-54a76e7f2335%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%2Bb6%2BDB4twJgnubgZL1NOnf2X85yCEp3czUhmwkiq-E8oUApcQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django 1.9.8 with mysql 'Commands out of sync; you can't run this command now' exception

2018-09-23 Thread thanh


I am a python developer and I am using Django 1.9.8 for my project.
I am having a problem with MySQL like below:

I have a model named 'Message' and sometimes when running this code, I got 
the exception 'Commands out of sync; you can't run this command now'

latest_message = Message.objects.order_by("-id").filter(example_field=1).first()

can you point out to me why does it happen and how to fix it?
thanks,
Thanh Tran

-- 
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/740fac2d-3399-45d3-bd96-54a76e7f2335%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Update django 1.8 project to 2.0 lts

2018-09-23 Thread Jason
django 2.x is not lts, next LTS version is 2.2, as said before.

That said, I'd break this into three chunks:

migrate 1.8 to 1.11
migrate 2.7 to 3.6 (or 3.7)
migrate 1.11 to 2.1 or 2.2, depending on the timing.  2.2 will be out in 
April 2019, which is seven months from now.

I would separate framework update from python version update to minimize 
bugs and simplify the upgrade process.

-- 
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/33fddf1a-1fa9-4d5c-8a91-0beab9f77be4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Update django 1.8 project to 2.0 lts

2018-09-23 Thread carlos
Django 2.0 Not LTS warning!! the next LTS Django version is 2.2

Cheers

On Sun, Sep 23, 2018 at 6:08 PM Mike Dewhirst  wrote:

> On 23/09/2018 11:15 PM, 'David Brown' via Django users wrote:
> > I have a large django project built in 1.8 with about 14 apps and a
> large amount of dependencies.
> >
> > I already have a good idea about how I'm going to update the 2.7 code to
> 3.6 or possibly just make it compatible with both, however, I'm not sure
> what is the best practice and most efficient way to refactor/upgrade the
> django framework to 2.0 from 1.8.
> >
> > Bare in mind this thousands of lines of code so efficiency in terms of
> work is crucial.
>
> I suggest bringing the Django code only as far as 1.11 in Python 2.7.
> Django 1.11 is a LTS version.
>
> Then I would advance the same code to Python 3.x and get that working as
> a separate ring-fenced project. You can do that away from production or
> using six and other dual-Python tricks you can also deploy 3.x code to
> production. I have been writing in 3.x and deploying in 2.7 for quite
> some time. One of these days I'll switch the production server to
> Python3 and drop 2.7.
>
> Only with Django 1.11 and Python 3.x working properly in production will
> I advance to the next Django 2.x LTS version
>
> Oh, and heaps of tests :)
>
> hth
>
> Mike
>
> >
> > Thanks in advance for all suggestions!
> >
>
> --
> 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/c04babcd-b1cf-4b0b-fdb6-854e9671c543%40dewhirst.com.au
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
att.
Carlos Rocha

-- 
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/CAM-7rO3rtp7LvwBwFpr29-i5ZuDBZ%2BH2V1u-74ZQn4XBy0fhfg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Update django 1.8 project to 2.0 lts

2018-09-23 Thread Mike Dewhirst

On 23/09/2018 11:15 PM, 'David Brown' via Django users wrote:

I have a large django project built in 1.8 with about 14 apps and a large 
amount of dependencies.

I already have a good idea about how I'm going to update the 2.7 code to 3.6 or 
possibly just make it compatible with both, however, I'm not sure what is the 
best practice and most efficient way to refactor/upgrade the django framework 
to 2.0 from 1.8.

Bare in mind this thousands of lines of code so efficiency in terms of work is 
crucial.


I suggest bringing the Django code only as far as 1.11 in Python 2.7. 
Django 1.11 is a LTS version.


Then I would advance the same code to Python 3.x and get that working as 
a separate ring-fenced project. You can do that away from production or 
using six and other dual-Python tricks you can also deploy 3.x code to 
production. I have been writing in 3.x and deploying in 2.7 for quite 
some time. One of these days I'll switch the production server to 
Python3 and drop 2.7.


Only with Django 1.11 and Python 3.x working properly in production will 
I advance to the next Django 2.x LTS version


Oh, and heaps of tests :)

hth

Mike



Thanks in advance for all suggestions!



--
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/c04babcd-b1cf-4b0b-fdb6-854e9671c543%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


error at re_path

2018-09-23 Thread shiva kumar
getting error saying page not found when using re_path for defining our own
url pattern.

re_path(r'^home/(?p[0-9]{4})/$',views.home1),

this was how i used the function and it showing error at ?p.


is there any mistake suggest a solution.

-- 
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/CAMsYeuHzbhA0Pu5gm7t0G4kuMENKf-CNPWQURHSLajGfhDskBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to open http://127.0.0.1:8000

2018-09-23 Thread 'Rohit' via Django users
I figured out the issue.

Port 8000 and 8080 are being used by Jenkins.

I tried to change it to 8282 and executed this line from the project folder 
in the command prompt:

python manage.py runserver 8282

Once the development server started, I typed the IP as below from the 
browser. It worked.

http://127.0.0.1:8282



On Sunday, September 23, 2018 at 11:35:56 PM UTC+5:30, SHUBHAM .SINGH. 
RATHORE wrote:
>
> Django-admin startaproject  and project name
>
> On Sun 23 Sep, 2018 11:29 pm 'Rohit' via Django users, <
> django...@googlegroups.com > wrote:
>
>> Hi,
>>
>> I am new to Django and started my first app. When I try to check the 
>> development server using http://127.0.0.1:8000, I am getting: 404 Not 
>> Found.
>>
>> How to fix 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...@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/428b49c6-673b-4881-a109-a8e992ccdd7e%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/9389919c-1d02-4ccb-b0a3-74b190cc5824%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to open http://127.0.0.1:8000

2018-09-23 Thread 'Rohit' via Django users
Django project I already created using PyCharm. The folder structure and 
basic .py files already there.



On Sunday, September 23, 2018 at 11:35:56 PM UTC+5:30, SHUBHAM .SINGH. 
RATHORE wrote:
>
> Django-admin startaproject  and project name
>
> On Sun 23 Sep, 2018 11:29 pm 'Rohit' via Django users, <
> django...@googlegroups.com > wrote:
>
>> Hi,
>>
>> I am new to Django and started my first app. When I try to check the 
>> development server using http://127.0.0.1:8000, I am getting: 404 Not 
>> Found.
>>
>> How to fix 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...@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/428b49c6-673b-4881-a109-a8e992ccdd7e%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/8562d49f-79e0-4934-b15d-93c3d72c69e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to open http://127.0.0.1:8000

2018-09-23 Thread 'Rohit' via Django users
I am using PyCharm. Do I still need to execute that code from command 
prompt?



On Sunday, September 23, 2018 at 11:35:56 PM UTC+5:30, SHUBHAM .SINGH. 
RATHORE wrote:
>
> Django-admin startaproject  and project name
>
> On Sun 23 Sep, 2018 11:29 pm 'Rohit' via Django users, <
> django...@googlegroups.com > wrote:
>
>> Hi,
>>
>> I am new to Django and started my first app. When I try to check the 
>> development server using http://127.0.0.1:8000, I am getting: 404 Not 
>> Found.
>>
>> How to fix 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...@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/428b49c6-673b-4881-a109-a8e992ccdd7e%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/8254bd86-4cb8-47bf-8cfe-e196a3d1604b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to open http://127.0.0.1:8000

2018-09-23 Thread SHUBHAM .SINGH. RATHORE
Django-admin startaproject  and project name

On Sun 23 Sep, 2018 11:29 pm 'Rohit' via Django users, <
django-users@googlegroups.com> wrote:

> Hi,
>
> I am new to Django and started my first app. When I try to check the
> development server using http://127.0.0.1:8000, I am getting: 404 Not
> Found.
>
> How to fix 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/428b49c6-673b-4881-a109-a8e992ccdd7e%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/CALkhXJX0OvhAYc-jbsiVbvEmOwQHcZc_XkH2Y6tu4bM4JtP0kQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Unable to open http://127.0.0.1:8000

2018-09-23 Thread 'Rohit' via Django users
Hi,

I am new to Django and started my first app. When I try to check the 
development server using http://127.0.0.1:8000, I am getting: 404 Not Found.

How to fix 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/428b49c6-673b-4881-a109-a8e992ccdd7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


what's the difference between TemplateView, ListView and DetailView ?

2018-09-23 Thread Mateusz
My answer was not fully on the topic. You shouldn't do what you want to do but 
if there's a real need for that...

You can add context by overriding get_context() method.

(context = super().get_context(); context['type'] = list; return context).

{% if type == list %}
This is a list
{% elif type == template %}
This is just a template
...

Or just e.g. context['list'] == True
And then:
{% if list %}
This is a list
{% if template %}
This is just a template
...

-- 
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/f63c6291-6f71-41b1-ac4b-6eb37ff5e5eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django - using intermediate user group model

2018-09-23 Thread Mateusz
Is that User [N] -- [N] Group with many to many through Enrollment 
(something like that: User [1] -- [N] Enrollment [N] -- [1] Group)? Then, 
the answer in this gist here .


W dniu piątek, 21 września 2018 20:16:05 UTC+2 użytkownik Fernando 
Balmaceda napisał:
>
> Hi everyone!
>
> I am trying to add a foreign key in a model to the table intermediary 
> between User and Group. Something like this:
>
> from django.db import models
> from django.contrib.auth.models import User
>
>
> class Enrollment(models.Model):
> 
> user_groups = models.ForeignKey(User.groups.through, on_delete=models.
> CASCADE)
>
> But when i try this, django throws an error:
>
> core.Enrollment.user_groups: (fields.E300) Field defines a relation with 
> model 'User_groups', which is either not installed, or is abstract.
>
> How can I achieve this?. 
> Using Django 2.0
>
> Thanks!
>
>

-- 
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/276ed34b-082f-4580-8852-ebee77be1889%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: serializer for multipele views

2018-09-23 Thread Mateusz
You probably solved that already but... You go to *.../api/bookings*/ while 
your urls.py makes a redirection for *.../api/booking *(there's an analogy 
to .../api/workspace from the right image).

W dniu niedziela, 23 września 2018 11:17:51 UTC+2 użytkownik Tim Vogt 
napisał:
>
> I have made an Rest api on django 2.0 with works fine with one api view 
> api/workspace
>
>
> but it does not show the data with the view of the booking form . Any tips 
> how to solve it?
> Tim
>
>
> #api/serializers.py
> from rest_framework import generics
>
> from rest_framework import serializers
>
> from workspace.models import Workspace_booking
>
> class Workspace_bookingSerializer(serializers.ModelSerializer):
> class Meta:
> model = Workspace_booking
> fields = ( 
> 'id','name','address','description','totalSpots','spotsTaken','location')
>
>
> class Bookings_bookingSerializer(serializers.ModelSerializer):
> class Meta:
> model = Workspace_booking
> fields = ('id','date','workplaceId','people','note')
>
>
> #api urls.py
>
> from django.urls import path
>
> from .views import  Workspace_bookingApiView ,   
> Workspace_bookingApiView_detail
> from .views import  Bookings_bookingApiView ,   Bookings_bookingApiView_detail
>
>
> urlpatterns = [
>
> path('workspace', Workspace_bookingApiView.as_view()),
>
> path('/', Workspace_bookingApiView_detail.as_view()),
>
> path('booking', Bookings_bookingApiView.as_view()),
>
> path('/', Bookings_bookingApiView_detail.as_view())
> ]
>
>
> #api views.py
>
> from django.shortcuts import render
>
> from rest_framework import generics
>
>
>
> from workspace.models import Workspace_booking
> from bookings.models import Bookings_booking
>
> from .serializers import Workspace_bookingSerializer
> from .serializers import Bookings_bookingSerializer
>
>
>
> class Workspace_bookingApiView(generics.ListAPIView):
> queryset = Workspace_booking.objects.all()
> serializer_class = Workspace_bookingSerializer
>
> class   
> Workspace_bookingApiView_detail(generics.RetrieveUpdateDestroyAPIView):
> queryset = Workspace_booking.objects.all()
> serializer_class = Workspace_bookingSerializer
>
>
> class Bookings_bookingApiView(generics.ListAPIView):
> queryset = Bookings_booking.objects.all()
> serializer_class = Bookings_bookingSerializer
>
> class   Bookings_bookingApiView_detail(generics.RetrieveUpdateDestroyAPIView):
> queryset = Bookings_booking.objects.all()
> serializer_class = Bookings_bookingSerializer
>
>

-- 
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/d638456d-eace-4ca2-9700-020ed958d4de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: what's the difference between TemplateView, ListView and DetailView ?

2018-09-23 Thread Mateusz

>
> Django provides base view classes which will suit a wide range of 
> applications. All views inherit from the View 
> 
>  
> class, which handles linking the view in to the URLs, HTTP method 
> dispatching and other simple features. RedirectView 
> 
>  
> is for a simple HTTP redirect, and TemplateView 
> 
>  
> extends the base class to make it also render a template.


TemplateView (docs 

)

> Renders a given template, with the context containing parameters captured 
> in the URL.

Use it when you want just to render some template, without getting objects 
from database. 

ListView (docs 

)

> A page representing a list of objects.

Use it when you want to represent multiple objects from your database on a 
list (single template with multiple objects -- e.g. a list of products that 
are available in the shop or list of to-dos...).

DetailView (docs 

)

> While this view is executing, self.object will contain the object that the 
> view is operating upon.

Use it when you want to represent single object from your database (single 
template with one object, detailed -- e.g. product page).


*Why to use DetailView and ListView instead of always using TemplateView?*Main 
reason is that using the views simplifies writing and reading the code. You 
can use built-in methods that do almost the whole job for you (actually 
they are used "automagically" and if you want them to do something else, 
e.g. add filtering to your ListView, you can just override them).


W dniu niedziela, 23 września 2018 15:47:17 UTC+2 użytkownik Gear Crew 
napisał:
I want to know when I use TemplateView , ListView and DetailView on my 
template code 

-- 
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/a20803dd-6590-468f-a023-c71d3ba1633b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Update django 1.8 project to 2.0 lts

2018-09-23 Thread Mateusz
This can take a lot of time but if you're really into this, you can see the 
the release notes for every version between 1.8 and 2.0 (especially for 
version 2.0 ) and seek 
for things you can change in your code that were optimised in the meantime.

W dniu niedziela, 23 września 2018 15:57:03 UTC+2 użytkownik David Brown 
napisał:
>
> I have a large django project built in 1.8 with about 14 apps and a large 
> amount of dependencies. 
>
> I already have a good idea about how I'm going to update the 2.7 code to 
> 3.6 or possibly just make it compatible with both, however, I'm not sure 
> what is the best practice and most efficient way to refactor/upgrade the 
> django framework to 2.0 from 1.8. 
>
> Bare in mind this thousands of lines of code so efficiency in terms of 
> work is crucial. 
>
> Thanks in advance for all suggestions!

-- 
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/3ef6cb3e-5c47-4660-88bd-566bcfe267e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to create form??

2018-09-23 Thread Mateusz
This may not seem simple, but it is.
1) You need a model with all the fields (docs 
),
2) Register that model to be visible on admin page (docs 

),
3) Create a forms.py file inside your app folder and form class inside that 
file (docs 
),
4) Create a simple template, it needs to have specific name or that name 
must be specified in a view from point 4 (same docs page as in 3),
5) Handle the form in views.py by adding a class-based FormView (docs 

),
6) Add the specific url to urls.py.

For more info about template creation visit: 
https://simpleisbetterthancomplex.com/article/2017/08/19/how-to-render-django-form-manually.html

W dniu niedziela, 23 września 2018 17:52:00 UTC+2 użytkownik Ansari Sabir 
napisał:
>
> How to create a form that collect information (like first name, last name, 
> email address, contact number, gender) and admin can see that information 
> in the /admin/ in django. 
>

-- 
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/94746cc2-2e64-4182-a659-be73848c4e66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to create form??

2018-09-23 Thread Jani Tiainen
Hi.

If you have done the official tutorial, part 4 is all about this exact
problem.


su 23. syysk. 2018 klo 18.51 Ansari Sabir  kirjoitti:

> How to create a form that collect information (like first name, last name,
> email address, contact number, gender) and admin can see that information
> in the /admin/ in django.
>
> --
> 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/71966989-c435-4d68-968b-6f36bdf4b34f%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/CAHn91ofxcSfFE8aJsX678eD6tQUEyNH3WYXENRQL1TiGAGyYFg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to create form??

2018-09-23 Thread Ansari Sabir
How to create a form that collect information (like first name, last name, 
email address, contact number, gender) and admin can see that information 
in the /admin/ in django. 

-- 
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/71966989-c435-4d68-968b-6f36bdf4b34f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Update django 1.8 project to 2.0 lts

2018-09-23 Thread Jani Tiainen
I suppose you do have good unittest code coverage so do gradual upgrades
(which is preferred upgrade path) and read release notes on each version.

2to3 tool is great help to check some obvious issues when upgrading to
Python 3.

su 23. syysk. 2018 klo 16.57 'David Brown' via Django users <
django-users@googlegroups.com> kirjoitti:

> I have a large django project built in 1.8 with about 14 apps and a large
> amount of dependencies.
>
> I already have a good idea about how I'm going to update the 2.7 code to
> 3.6 or possibly just make it compatible with both, however, I'm not sure
> what is the best practice and most efficient way to refactor/upgrade the
> django framework to 2.0 from 1.8.
>
> Bare in mind this thousands of lines of code so efficiency in terms of
> work is crucial.
>
> Thanks in advance for all suggestions!
>
> --
> 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/d6307d12-8920-434b-b5ec-e9b72c0c3443%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/CAHn91oc8Edc2T2g5dkJ%2BaqEsaNT1CH%3DtmYjq4TEnmY%3DagHN0VQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Update django 1.8 project to 2.0 lts

2018-09-23 Thread 'David Brown' via Django users
I have a large django project built in 1.8 with about 14 apps and a large 
amount of dependencies.

I already have a good idea about how I'm going to update the 2.7 code to 3.6 or 
possibly just make it compatible with both, however, I'm not sure what is the 
best practice and most efficient way to refactor/upgrade the django framework 
to 2.0 from 1.8. 

Bare in mind this thousands of lines of code so efficiency in terms of work is 
crucial.

Thanks in advance for all suggestions!

-- 
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/d6307d12-8920-434b-b5ec-e9b72c0c3443%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error at OneToOneField in models while creating new models class

2018-09-23 Thread Adolfo Cueto
First you have to change your model name Class names starts with 
uppercase...

My friend.. you are not making migrations... look at you have to do this:


1. Delete your migration folder
2. Delete you app table manually (DROP table)
3. python manage.py makemigrations app_name
4. migrate

that's all

El sábado, 22 de septiembre de 2018, 4:10:45 (UTC-5), Srinivas Gadi 
escribió:
>
> HI All,
>
> I am facing below error while creating a new model class.
> the error pop up only at this line "user = models.OneToOneField(User)"
> *"E1120:No value for argument 'on_delete' in constructor call"*
>
> from django.db import models
> from django.contrib.auth.models import User
>
> class userProfile(models.Model):
> user = models.OneToOneField(User)
>
> If I add "user = models.OneToOneField(User,*on_delete=models.CASCADE*)" 
> the error got subsided but the new class "userProfile" is not appearing 
> in admin page, under Users tab.
>
> Could some one please guide me how to fix this ?
>
> -- 
> Srinivas .G
>   9966559383
>

-- 
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/42ee3cf4-5347-4371-b9aa-343aa946c191%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Sample Datbase data

2018-09-23 Thread Gear Crew
Please more explain about your issues 

On Friday, 21 September 2018 13:43:47 UTC+2, Sukla Nag wrote:
>
> Is it possible to download table data of sample databases in the tutorial ?
>

-- 
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/6a819226-f27e-4ca6-ad99-8e3b0973fabf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


what's the difference between TemplateView, ListView and DetailView ?

2018-09-23 Thread Gear Crew
I want to know when I use  TemplateView , ListView and DetailView on my 
template code 

-- 
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/38a51a8f-aac7-474c-a557-3aebd5531eb2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: serializer for multipele views

2018-09-23 Thread Jason
the screenshot of the error has a trailing slash in the URL, while the 
working response doesn;t.

-- 
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/6882bfca-c558-4a17-baf2-fb49702982f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error at OneToOneField in models while creating new models class

2018-09-23 Thread Srinivas Gadi
Yes, provided the migrations out put in the second mail

On Sat, 22 Sep 2018, 17:11 Matthew Pava,  wrote:

> Did you try running your migrations?
>
> Get Outlook for Android 
>
>
>
>
> On Sat, Sep 22, 2018 at 5:07 AM -0500, "Srinivas Gadi" <
> srini@gmail.com> wrote:
>
> Adding more and complete details:
>> I am facing below error while creating a new model class.
>> the error pops up only at this line "user = models.OneToOneField(User)"
>> *"E1120:No value for argument 'on_delete' in constructor call"*
>>
>> section/models.py
>>
>> from django.db import modelsfrom django.contrib.auth.models import User
>> class userProfile(models.Model):
>> user = models.OneToOneField(User)
>>
>> admin.py
>>
>> from django.contrib import adminfrom section.models import userProfile
>>
>> admin.site.register(userProfile)
>>
>> If I add below entry with "on_delete=models.CASCADE"
>>
>> user = models.OneToOneField(User,on_delete=models.CASCADE)
>>
>> the error got subsided but the new class "userProfile" is not appearing
>> in admin page, under Users tab.
>>
>> Also, run migrations:
>>
>> C:\Users\srini\djangoProjects\college>python manage.py makemigrationsNo 
>> changes detected
>>
>> C:\Users\srini\djangoProjects\college>python manage.py migrateOperations to 
>> perform:Apply all migrations: admin, auth, contenttypes, sessionsRunning 
>> migrations:No migrations to apply.
>>
>> Could someone please guide me how to fix this?
>>
>> On Sat, Sep 22, 2018 at 2:40 PM Srinivas Gadi 
>> wrote:
>>
>>> HI All,
>>>
>>> I am facing below error while creating a new model class.
>>> the error pop up only at this line "user = models.OneToOneField(User)"
>>> *"E1120:No value for argument 'on_delete' in constructor call"*
>>>
>>> from django.db import models
>>> from django.contrib.auth.models import User
>>>
>>> class userProfile(models.Model):
>>> user = models.OneToOneField(User)
>>>
>>> If I add "user = models.OneToOneField(User,*on_delete=models.CASCADE*)"
>>> the error got subsided but the new class "userProfile" is not appearing
>>> in admin page, under Users tab.
>>>
>>> Could some one please guide me how to fix this ?
>>>
>>> --
>>> Srinivas .G
>>>   9966559383
>>>
>>
>>
>> --
>> Srinivas .G
>>   9966559383
>>
>> --
>> 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/CAPC7spgQAR0e28KtZG4Ljt%3Dk4Su39qipvZJaRy4%3DCJbD6CTMCA%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/D9BEB906A6B607A4.5302fd9d-847e-4878-88de-82caf2f9c69b%40mail.outlook.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/CAPC7spiyJ5_kCtVfwpui2TALrQw-fpM7O40QucTryeX5qst7Og%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.