Re: Pagination - Not Working

2019-02-18 Thread Siddharth Tamang
Please send your views.py. You must have a home page or index page where
you want to paginate records.

On Tue, Feb 19, 2019 at 11:23 AM Aakash Baranwal 
wrote:

> I have also used Ajax with that. It's load more button is not working, it
> is showing the 10 posts which is the limit I set in the beginning, but not
> going beyond that.
>
> On Tue, Feb 19, 2019 at 11:13 AM Siddharth Tamang <
> tamangsiddhart...@gmail.com> wrote:
>
>> Are you trying pagination using JavaScript or Django?
>>
>> On Mon, Feb 18, 2019 at 11:47 PM Aakash Baranwal 
>> wrote:
>>
>>> Hello Everyone,
>>>
>>> I am new to Django and working towards developing a web app where 10
>>> posts appear at a time with a "Load More" option given at last which when
>>> clicked shows the next 10 posts. I am not able to find what is going wrong
>>> with the code.
>>>
>>> Also, it is not showing the character counter for the textbox, so kindly
>>> help me with that as well.
>>>
>>> I am sending the screenshot of the code, pagination.py file.
>>>
>>> Thank You in advance
>>>
>>> --
>>> 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/CALr9hQ02EKRB%3DUjPfgjX1Q1%2BG_QxxBovM7Xv_J9Y-Q%3DiwMLo_A%40mail.gmail.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> --
>> Thank you
>> Siddharth Tamang
>> AWS Certified Solutions Architect - Associate
>>
>> --
>> 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/CADBOudsyrwDg%3DzcG3SgFMVnosOUtym%2BeR3d7UPXEa9GnRz7Opw%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/CALr9hQ1CRSweCoycg0AfyiwG9LFb%3DZ2NL7oW7BMPuBg8qk%2B2GA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Thank you
Siddharth Tamang
AWS Certified Solutions Architect - Associate

-- 
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/CADBOudtmJpskP-K_5%3D24BOXExeNq0%3DreM4nQZbWLaVrJVo0k8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Pagination - Not Working

2019-02-18 Thread Aakash Baranwal
I have also used Ajax with that. It's load more button is not working, it
is showing the 10 posts which is the limit I set in the beginning, but not
going beyond that.

On Tue, Feb 19, 2019 at 11:13 AM Siddharth Tamang <
tamangsiddhart...@gmail.com> wrote:

> Are you trying pagination using JavaScript or Django?
>
> On Mon, Feb 18, 2019 at 11:47 PM Aakash Baranwal 
> wrote:
>
>> Hello Everyone,
>>
>> I am new to Django and working towards developing a web app where 10
>> posts appear at a time with a "Load More" option given at last which when
>> clicked shows the next 10 posts. I am not able to find what is going wrong
>> with the code.
>>
>> Also, it is not showing the character counter for the textbox, so kindly
>> help me with that as well.
>>
>> I am sending the screenshot of the code, pagination.py file.
>>
>> Thank You in advance
>>
>> --
>> 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/CALr9hQ02EKRB%3DUjPfgjX1Q1%2BG_QxxBovM7Xv_J9Y-Q%3DiwMLo_A%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> Thank you
> Siddharth Tamang
> AWS Certified Solutions Architect - Associate
>
> --
> 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/CADBOudsyrwDg%3DzcG3SgFMVnosOUtym%2BeR3d7UPXEa9GnRz7Opw%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/CALr9hQ1CRSweCoycg0AfyiwG9LFb%3DZ2NL7oW7BMPuBg8qk%2B2GA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Pagination - Not Working

2019-02-18 Thread Aakash Baranwal
I am trying to do it using Django. I used Django Rest Framework API
Guide-Pagination for reference

On Tue, Feb 19, 2019 at 11:13 AM Siddharth Tamang <
tamangsiddhart...@gmail.com> wrote:

> Are you trying pagination using JavaScript or Django?
>
> On Mon, Feb 18, 2019 at 11:47 PM Aakash Baranwal 
> wrote:
>
>> Hello Everyone,
>>
>> I am new to Django and working towards developing a web app where 10
>> posts appear at a time with a "Load More" option given at last which when
>> clicked shows the next 10 posts. I am not able to find what is going wrong
>> with the code.
>>
>> Also, it is not showing the character counter for the textbox, so kindly
>> help me with that as well.
>>
>> I am sending the screenshot of the code, pagination.py file.
>>
>> Thank You in advance
>>
>> --
>> 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/CALr9hQ02EKRB%3DUjPfgjX1Q1%2BG_QxxBovM7Xv_J9Y-Q%3DiwMLo_A%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> Thank you
> Siddharth Tamang
> AWS Certified Solutions Architect - Associate
>
> --
> 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/CADBOudsyrwDg%3DzcG3SgFMVnosOUtym%2BeR3d7UPXEa9GnRz7Opw%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/CALr9hQ1jGL83EZ5u-FrGmh9c1q6kYNCHUup%3D4CzGhHVi%2BJakSA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Pagination - Not Working

2019-02-18 Thread Siddharth Tamang
Are you trying pagination using JavaScript or Django?

On Mon, Feb 18, 2019 at 11:47 PM Aakash Baranwal 
wrote:

> Hello Everyone,
>
> I am new to Django and working towards developing a web app where 10 posts
> appear at a time with a "Load More" option given at last which when clicked
> shows the next 10 posts. I am not able to find what is going wrong with the
> code.
>
> Also, it is not showing the character counter for the textbox, so kindly
> help me with that as well.
>
> I am sending the screenshot of the code, pagination.py file.
>
> Thank You in advance
>
> --
> 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/CALr9hQ02EKRB%3DUjPfgjX1Q1%2BG_QxxBovM7Xv_J9Y-Q%3DiwMLo_A%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Thank you
Siddharth Tamang
AWS Certified Solutions Architect - Associate

-- 
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/CADBOudsyrwDg%3DzcG3SgFMVnosOUtym%2BeR3d7UPXEa9GnRz7Opw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Providing help on a website (basic CMS for on-site site documentation)

2019-02-18 Thread Bernd Wechner
I'm at the point of wanting to write some help for a website, the standard 
helpfile sort of scenario ;-). If that means little to you, just a 
hierarchy of pages that document things and can be linked. 

I wrote page one with the Django flatpages app:

https://docs.djangoproject.com/en/2.1/ref/contrib/flatpages/

But it's not real comfy in terms of editing and maintaining. So I looked 
on-line for solutions and of course nothing with "help" in the search terms 
is going anywhere fast (finds me a lot of help about Django ;-). so better 
keywordss needed but I have found a pile of maybe options and am suddenly 
bamboozled by what is vogue, current, maintained, has a lasting future etc.

https://github.com/klen/django_markdown

Untouched in 4 years with 22 open issues Hmm.

And this looks nice:

https://github.com/mjr27/django-flatpages-tinymce

but untouched in 7 years and 4 open issues. 

Now untouched doesn't mean bad, could just be mature, stable and works 
perfectly, already fro 7 years. These are the things it's hard to gauge. 
But if I'm looking at TinyMCE how about:

https://github.com/aljosa/django-tinymce

on which it depends. NO bad, updated a month ago to make it work with 
Django 2.1 so seems alive! But my site is math heavy so I want equation 
ease so how about:

And this looks good:

https://www.codecogs.com/latex/integration/tinymce_v3/install.php

This looks maybe:

https://github.com/iCAPLyon1/tinymce-formula

This looks unconvincing:

https://github.com/foraker/tinymce_equation_editor

and do we want this:

https://github.com/Tivix/django-flatpages-nav

or this as well:

Or hang on why do this piecemeal why not use Wagtail from the word go:

http://docs.wagtail.io/en/v2.4/index.html

Or would wagtail introduce too much coordination trouble between its 
templates and my sites ... etc. etc. I'm full of questions and really just 
wondering, is there a canonical solution to a site documentation page 
hierarchy and managing it nicely?

Regards,

Bernd.


-- 
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/f74dff14-7ea1-45b3-bfb3-82ecc9c66799%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Websocket 200 error

2019-02-18 Thread flora . xiaoyun . huang
I am guessing maybe there is an issue with the redis-server? *The log I 
received from Daphne*:
2019-02-18 21:07:54,543 ERRORError trying to receive messages: Error 
running script (call to f_3640886a0c8901ca9188f5f7a5f7a346145b9c5f): 
@user_script:3: @user_script: 3: -MISCONF Redis is configured to save RDB 
snapshots, but is currently not able to persist on disk. Commands that may 
modify the data set are disabled. Please check Redis logs for details about 
the error.

So I check *redis log*:
[1418] 18 Feb 16:09:27.071 * 1 changes in 900 seconds. Saving...
[1418] 18 Feb 16:09:27.072 * Background saving started by pid 2834
[2834] 18 Feb 16:09:27.073 # Failed opening .rdb for saving: Permission 
denied
[1418] 18 Feb 16:09:27.172 # Background saving error

I searched ways to solve the problem and set the permission of .rdb to 777. 
But still has this error in redis log.

I also find I cannot shutdown and restart redis. 

When I type redis-server in the command line, the log info:
[2892] 18 Feb 16:14:32.457 # Warning: no config file specified, using the 
default config. In order to specify a config file use redis-server 
/path/to/redis.conf
[2892] 18 Feb 16:14:32.459 # Unable to set the max number of files limit to 
10032 (Operation not permitted), setting the max clients configuration to 
3984.
[2892] 18 Feb 16:14:32.459 # Creating Server TCP listening socket *:6379: 
bind: Address already in use

*These are the redis processes running:*
redis-ser  1418redis4u  IPv6  14515  0t0  TCP *:6379 (LISTEN)
redis-ser  1418redis5u  IPv4  14516  0t0  TCP *:6379 (LISTEN)
redis-ser  1418redis6u  IPv6 203617  0t0  TCP 
localhost:6379->localhost:34108 (ESTABLISHED)
redis-ser  1418redis7u  IPv6 202944  0t0  TCP 
localhost:6379->localhost:34104 (ESTABLISHED)

On Monday, February 18, 2019 at 4:14:44 PM UTC-5, flora.xia...@gmail.com 
wrote:
>
> Hi,
>
> The real-time discussion function (supported by Daphne) on my website is 
> not working (Other non-real-time functions are good). The console echos: 
> "WebSocket connection to 'ws://xxxforum/room_xxx/' failed: Error during 
> WebSocket handshake: Unexpected response code: 200". I've went through the 
> blog posts and the documentation but couldn't find a solution. Can anyone 
> help?
>
> I am attaching information that I think is needed. If you need any other 
> information please let me know.
>
> *The non-real-time part is supported by uwsgi* (I know it can be 
> supported by Daphne too. But since the real-time part is not working I 
> decide to use uwsgi): 
> uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket=666 
> --processes=6
>
> *daphne*:
> daphne mysite.asgi:channel_layer --port 8000 --bind 0.0.0.0 -v2 &
> python manage.py runworker -v2 &
>
> *nginx configuration:*
> upstream websocket { server 0.0.0.0:8000; } server { listen 80; 
> server_name mysite.com; charset utf-8; client_max_body_size 20M; location 
> /static { alias /path/to/mysite/static; } location / { include 
> /etc/nginx/uwsgi_params;
> uwsgi_pass unix:///path/to/mysite/mysite.sock; } location /ws { proxy_pass 
> http://websocket; proxy_http_version 1.1; proxy_set_header Upgrade 
> $http_upgrade;
> proxy_set_header Connection "upgrade";
> proxy_redirect off;
> proxy_set_header   Host $host;
> proxy_set_header   X-Real-IP $remote_addr;
> proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
> proxy_set_header   X-Forwarded-Host $server_name;
> }
> }
>
> One thing that I don't understand is that if I try to use Daphne to 
> support both real-time and non-real-time communication by deleting the 
> uwsgi block "location / {}" and renaming "location /ws {}" to "location / 
> {}" the nginx service cannot be restarted. Does it suggest any bug?
>
> *first few lines in .js related to the discussion function:*
> $(function() {
> var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws"; var 
> chatsock = new ReconnectingWebSocket(ws_scheme + '://' + 
> window.location.host + window.location.pathname);
> ..
>
>

-- 
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/4886f1be-5177-405b-9b90-43603db779ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


getting related data from database other than default

2019-02-18 Thread progmgppers
Hi,

I'm having some trouble getting data from a database with foreign-keys. 

Normally a query-set retrieved like this, obj = 
model.objects.all().filter(id=pk).select_related(), would give me the table 
row data, and the related row data from another table defined in the model, 
of the default database.
And normally if I say, obj = 
model.objects.all().filter(id=pk).using('somedatabase'), I get the data 
from the row in the using defined database.

But I cant seem to get the related data from a using database. For 
instance, obj = 
model.objects.all().filter(id=pk).select_related().using('somedatabase'), 
gives me all the data from the 'using' database but never any of the 
related data of the 'using' database.

Does anyone have any ideas?

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/a5ba1a3c-9358-4c37-8cdd-5103c221d072%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


templates and Views

2019-02-18 Thread mohamed khaled
I think this link can help you 
https://www.google.com/url?sa=t=web=j=https://stackoverflow.com/questions/12187751/django-pass-multiple-models-to-one-template=2ahUKEwimi5aqosbgAhUJtRoKHaiCCYYQjjgwAHoECAcQAQ=AOvVaw0pFQWtYwtjrd03LHLWZ8rz

-- 
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/814c3364-7677-40db-b50f-e92c5c60ebbd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Re: Composite Primary / Foreign Key support

2019-02-18 Thread Simone Federici
Lance,

sincerely, nobody take care about that feature because that's needed just
for legacy db.
The number of applications with on legacy db is less than 0.01% of the
django applications.
There are some workaround for that applications, for example use SQL
Alchemy.

I implemented a CompositeKey Dajngo feature for Django 1.4.  It is
completly working also for the Generic Keys, concatening escaped keys.
There was also a draft to implement the indexes. However, Django core team
is evolving the platform so quickly (good for the framework) and the
library is not mantained anymore. On Dajngo 1.6 I had should rewrote it
completly.

In the end, now I understand why the core team don't care about the
feature. Forget it.


Il giorno lun 18 feb 2019 alle ore 09:28 'Ellinghaus, Lance J' via Django
users  ha scritto:

> NONCONFIDENTIAL // EXTERNAL
> So, basically, Django will not be supporting Composite Primary Keys in the
> future?
>
> Lance
>
> -Original Message-
> From: django-users@googlegroups.com  On
> Behalf Of Michal Petrucha
> Sent: Monday, February 11, 2019 8:34 AM
> To: Django users 
> Subject: [External] Re: Composite Primary / Foreign Key support
>
> NONCONFIDENTIAL // EXTERNAL
>
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA512
>
> On Mon, Feb 11, 2019 at 01:08:41AM -0800, 'Lance Ellinghaus' via Django
> users wrote:
> > I have seen references to people adding the support of composite
> > primary keys to Django for years, but it does not look like it has been
> added.
> >
> > I have a number of legacy databases that I cannot add fields to but
> > need to be able to be queried through Django. They are read-only tables.
> > A number of the tables are also related through Composite Foreign Keys
> > and I have seen some addons but not sure what is fully supported.
> >
> > I am trying to use Django 2.1.5.
> >
> > Any help or ideas would be appreciated, and saying  "Add a field to
> > your tables" is not an option.
> >
> > Thank you.
>
> Hi Lance,
>
> I haven't been on top of this in recent years, but let me try.
>
> When it comes to just composite primary keys, as long as you only need
> read access, you might be able to get away with marking an arbitrary field
> as the primary key. Using a non-unique field as the primary key would make
> any writes to the database dangerous, but that's not your case here.
> However, you also lose the invariant that filtering on the “pk” field alias
> will match at most one row, which means the admin would probably be off the
> table, too – since that assumes the “pk” is, in fact, unique, and the same
> holds for any other package that makes use of “pk”. You should still be
> okay in your own code, though.
>
> For composite foreign keys, there is nowadays a private, undocumented API,
> ForeignObject, which is what ForeignKey builds on. The general
> ForeignObject lets you specify multiple fields that make up the relation,
> you should be able to find some examples in the test suite (there is a
> foreign_object package in there). Keep in mind that this is an internal
> API, so it might change without warning.
>
> Good luck,
>
> Michal
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1
>
> iQIcBAEBCgAGBQJcYXniAAoJEHA7T/IPM/kl8EAP/Rzaxqe0bDO6vkxb4/Mmmj5S
> 62t6Cfm3VqqK6NxYjRXG904jKwDI4HMH1SAs5fdVMh9vf+VBj/S5bcIpQbesqXbh
> wbkcIn+mmnfhLDaHOGunYqp76tscBJv/rtxJZaX5NRLp7OraCWtbjRBtiw1fJ/tl
> iJD0HRIk9zn0pqyX8GjeAyM0UR+uL1wwrvz8Ur85ASsc8pFThTP6ZMQoaEIgo9D+
> HB3XfrhiOMd5Nb2SbjG4KCRe7alpFx83nuY53YVsv+8X+Nqp4Ndi7ch2Ni3jxxHf
> R7qVJYsMp/l72CNb6KiT85sb6PwQyeVdvU78cXKjkIKDirskGgQIEW2OvK+ZXC3B
> Aj4I+AMFXEKje8ITfW3/s/v+UNvVTNZHYC5NPZ6o50+YJFDoiwb0mpQMdUredWZk
> nT2cYMgyPQA/XKN9w5vUCNbTebPG/AA7yCthXbOrHn9Xl+kICkXRjjl9fHRUs55Q
> wgPqz0CFXPKaE+JFt/NABJzdSrki1y587GHsOb7hKFiQwS8DHU8WOMXkR3BGKEtN
> q0gebcqKvVnjRwLLsBvB0h3uI/yifgBTp8G8/+tZ0WuNdongTe+yPzchxuRjgx10
> e70xtBjgsyCQGRB3CPsgR2UelQOtAEt8ZyYwyPF5sQYOvQg1xjcYp87FqfqflSTE
> 6aQIMkXhKjKazmc/ew9F
> =Ji5Z
> -END PGP SIGNATURE-
>
> --
> 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/20190211133426.GV10973%40konk.org
> .
> 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
> 

Re: Websocket 200 error

2019-02-18 Thread flora . xiaoyun . huang
Thank you in advance!

On Monday, February 18, 2019 at 4:14:44 PM UTC-5, flora.xia...@gmail.com 
wrote:
>
> Hi,
>
> The real-time discussion function (supported by Daphne) on my website is 
> not working (Other non-real-time functions are good). The console echos: 
> "WebSocket connection to 'ws://xxxforum/room_xxx/' failed: Error during 
> WebSocket handshake: Unexpected response code: 200". I've went through the 
> blog posts and the documentation but couldn't find a solution. Can anyone 
> help?
>
> I am attaching information that I think is needed. If you need any other 
> information please let me know.
>
> *The non-real-time part is supported by uwsgi* (I know it can be 
> supported by Daphne too. But since the real-time part is not working I 
> decide to use uwsgi): 
> uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket=666 
> --processes=6
>
> *daphne*:
> daphne mysite.asgi:channel_layer --port 8000 --bind 0.0.0.0 -v2 &
> python manage.py runworker -v2 &
>
> *nginx configuration:*
> upstream websocket { server 0.0.0.0:8000; } server { listen 80; 
> server_name mysite.com; charset utf-8; client_max_body_size 20M; location 
> /static { alias /path/to/mysite/static; } location / { include 
> /etc/nginx/uwsgi_params;
> uwsgi_pass unix:///path/to/mysite/mysite.sock; } location /ws { proxy_pass 
> http://websocket; proxy_http_version 1.1; proxy_set_header Upgrade 
> $http_upgrade;
> proxy_set_header Connection "upgrade";
> proxy_redirect off;
> proxy_set_header   Host $host;
> proxy_set_header   X-Real-IP $remote_addr;
> proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
> proxy_set_header   X-Forwarded-Host $server_name;
> }
> }
>
> One thing that I don't understand is that if I try to use Daphne to 
> support both real-time and non-real-time communication by deleting the 
> uwsgi block "location / {}" and renaming "location /ws {}" to "location / 
> {}" the nginx service cannot be restarted. Does it suggest any bug?
>
> *first few lines in .js related to the discussion function:*
> $(function() {
> var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws"; var 
> chatsock = new ReconnectingWebSocket(ws_scheme + '://' + 
> window.location.host + window.location.pathname);
> ..
>
>

-- 
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/2bf2a20d-2650-49e6-a9e3-f0602b498a0a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Websocket 200 error

2019-02-18 Thread flora . xiaoyun . huang
Hi,

The real-time discussion function (supported by Daphne) on my website is 
not working (Other non-real-time functions are good). The console echos: 
"WebSocket connection to 'ws://xxxforum/room_xxx/' failed: Error during 
WebSocket handshake: Unexpected response code: 200". I've went through the 
blog posts and the documentation but couldn't find a solution. Can anyone 
help?

I am attaching information that I think is needed. If you need any other 
information please let me know.

*The non-real-time part is supported by uwsgi* (I know it can be supported 
by Daphne too. But since the real-time part is not working I decide to use 
uwsgi): 
uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket=666 
--processes=6

*daphne*:
daphne mysite.asgi:channel_layer --port 8000 --bind 0.0.0.0 -v2 &
python manage.py runworker -v2 &

*nginx configuration:*
upstream websocket { server 0.0.0.0:8000; } server { listen 80; server_name 
mysite.com; charset utf-8; client_max_body_size 20M; location /static { 
alias /path/to/mysite/static; } location / { include 
/etc/nginx/uwsgi_params;
uwsgi_pass unix:///path/to/mysite/mysite.sock; } location /ws { proxy_pass 
http://websocket; proxy_http_version 1.1; proxy_set_header Upgrade 
$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_set_header   Host $host;
proxy_set_header   X-Real-IP $remote_addr;
proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header   X-Forwarded-Host $server_name;
}
}

One thing that I don't understand is that if I try to use Daphne to support 
both real-time and non-real-time communication by deleting the uwsgi block 
"location / {}" and renaming "location /ws {}" to "location / {}" the nginx 
service cannot be restarted. Does it suggest any bug?

*first few lines in .js related to the discussion function:*
$(function() {
var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws"; var 
chatsock = new ReconnectingWebSocket(ws_scheme + '://' + 
window.location.host + window.location.pathname);
..

-- 
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/784a9296-059c-4a74-b952-cc9e6c8db709%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: REG: Why my django email settings not sending email notifications?

2019-02-18 Thread Kiran Capoor
Hi Amitesh,

>From my experience, You need to go to Google’s settings and enable access to 
>‘less secure apps’. That will let you send emails freely from your django dev 
>environment. Do so at your own risk, as any less secure app can use your email 
>and password. I would suggest you create a dummy/ Dev only gmail account.

Regards,
Kiran Capoor

Sent from my iPhone

> On 18-Feb-2019, at 13:41, Siddharth Tamang  
> wrote:
> 
> if you have MFA enabled on your gmail, you may have to disable it 
> 
>> On Mon, Feb 18, 2019 at 1:08 PM Onkar Narkar  
>> wrote:
>> 
>> Hi Amitesh,
>> 
>>  Are you getting some error like this:
>> smtplib.SMTPAuthenticationError: (534, b'5.7.9 Application-specific password 
>> required. Learn more at\n5.7.9  
>> https://support.google.com/mail/?p=InvalidSecondFactor 128sm18480521pfx.7 - 
>> gsmtp')
>> 
>> If this is the case, you need to specify application specific password 
>> instead of your nornal in gmail password.
>> 
>>> On Sunday, 17 February 2019 14:49:35 UTC+5:30, Amitesh Sahay wrote:
>>> I have created a registration page that sends an email notification on 
>>> successful registration. I do have my email notification in place. But it 
>>> doesn't seem to be working, neither it is throwing any error. Below is the 
>>> code snippet.
>>> views.py
>>> 
>>> def register(request):
>>> validators = [MinimumLengthValidator, NumberValidator, 
>>> UppercaseValidator]
>>> if request.method == 'POST':
>>> first_name = request.POST['first_name']
>>> last_name = request.POST['last_name']
>>> email = request.POST['email']
>>> username = request.POST['username']
>>> password = request.POST['password']
>>> try:
>>> for validator in validators:
>>> validator().validate(password)
>>> except ValueError as e:
>>> messages.error(request, str(e))
>>> return redirect('register')
>>> password2 = request.POST['password2']
>>> 
>>> # check if the password match
>>> if password == password2:
>>> 
>>> if User.objects.filter(username=username).exists():
>>> messages.error(request, 'username already exist')
>>> return redirect('register')
>>> else:
>>> if User.objects.filter(email=email).exists():
>>> messages.error(request, 'Registration Failed - Try 
>>> different email address')
>>> return redirect('register')
>>> else:
>>> user = User.objects.create_user(username=username, 
>>> password=password, email=email,
>>> first_name=first_name, 
>>> last_name=last_name)
>>> user.save()
>>> messages.success(request, 'Registration complete, 
>>> please proceed to login')
>>> return redirect('register')
>>> else:
>>> messages.error(request, 'password dose not match')
>>> return redirect('register')
>>> else:
>>> return render(request, 'ACCOUNTS/register.html')
>>> 
>>> 
>>> def ThankYou(request, register):
>>> if request.method == 'POST':
>>> if register.is_valid():
>>> save_it = register.save(commit=False)
>>> save_it.save()
>>> subject = 'Registration successful'
>>> message = 'Thank you for registration, please continue with 
>>> the login'
>>> from_email = settings.EMAIL_HOST_USER
>>> to_list = [save_it.email, settings.EMAIL_HOST_USER]
>>> try:
>>> send_mail(
>>> subject,
>>> message,
>>> from_email,
>>> [to_list],
>>> fail_silently=False,
>>> )
>>> except ValueError:
>>> return HttpResponse('Invalid header found.')
>>> else:
>>> messages.success(request, 'thank you ')
>>> return redirect('register')
>>> else:
>>> return redirect('index')
>>> Below is my settings.py
>>> 
>>> EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
>>> EMAIL_USE_TLS = False
>>> EMAIL_HOST = 'smtp.gmail.com'
>>> EMAIL_PORT = 587
>>> EMAIL_HOST_USER = 'ami@gmail.com'
>>> EMAIL_HOST_PASSWORD = '123'
>>> DEFAULT_FROM_EMAIL = 'ami@gmail.com'
>>> I have gone through a couple of Stackoverflow posts and made some changes 
>>> as suggested. But they do not seem to have any effect. Below is one of the 
>>> link.
>>> 
>>> Django Doesn't Send Email Notifications
>>> 
>>> Regards,
>>> Amitesh Sahay
>>> 91-750 797 8619
>> 
>> -- 
>> 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 

Re: Re: Composite Primary / Foreign Key support

2019-02-18 Thread Markus Holtermann
There's general interest in having support for composite keys and composite 
foreign key. It's just that nobody has implemented it. 

There are proposals among the DEPs that layout ideas how they could be 
implemented:

- https://github.com/django/deps/blob/master/draft/0191-composite-fields.rst
- 
https://github.com/django/deps/blob/master/draft/0192-standalone-composite-fields.rst

On Mon, Feb 18, 2019, at 9:28 AM, 'Ellinghaus, Lance J' via Django users wrote:
> NONCONFIDENTIAL // EXTERNAL
> So, basically, Django will not be supporting Composite Primary Keys in 
> the future?
> 
> Lance
> 
> -Original Message-
> From: django-users@googlegroups.com  On 
> Behalf Of Michal Petrucha
> Sent: Monday, February 11, 2019 8:34 AM
> To: Django users 
> Subject: [External] Re: Composite Primary / Foreign Key support
> 
> NONCONFIDENTIAL // EXTERNAL
> 
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA512
> 
> On Mon, Feb 11, 2019 at 01:08:41AM -0800, 'Lance Ellinghaus' via Django 
> users wrote:
> > I have seen references to people adding the support of composite 
> > primary keys to Django for years, but it does not look like it has been 
> > added.
> >
> > I have a number of legacy databases that I cannot add fields to but 
> > need to be able to be queried through Django. They are read-only tables.
> > A number of the tables are also related through Composite Foreign Keys 
> > and I have seen some addons but not sure what is fully supported.
> >
> > I am trying to use Django 2.1.5.
> >
> > Any help or ideas would be appreciated, and saying  "Add a field to 
> > your tables" is not an option.
> >
> > Thank you.
> 
> Hi Lance,
> 
> I haven't been on top of this in recent years, but let me try.
> 
> When it comes to just composite primary keys, as long as you only need 
> read access, you might be able to get away with marking an arbitrary 
> field as the primary key. Using a non-unique field as the primary key 
> would make any writes to the database dangerous, but that's not your 
> case here. However, you also lose the invariant that filtering on the 
> “pk” field alias will match at most one row, which means the admin 
> would probably be off the table, too – since that assumes the “pk” is, 
> in fact, unique, and the same holds for any other package that makes 
> use of “pk”. You should still be okay in your own code, though.
> 
> For composite foreign keys, there is nowadays a private, undocumented 
> API, ForeignObject, which is what ForeignKey builds on. The general 
> ForeignObject lets you specify multiple fields that make up the 
> relation, you should be able to find some examples in the test suite 
> (there is a foreign_object package in there). Keep in mind that this is 
> an internal API, so it might change without warning.
> 
> Good luck,
> 
> Michal
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1
> 
> iQIcBAEBCgAGBQJcYXniAAoJEHA7T/IPM/kl8EAP/Rzaxqe0bDO6vkxb4/Mmmj5S
> 62t6Cfm3VqqK6NxYjRXG904jKwDI4HMH1SAs5fdVMh9vf+VBj/S5bcIpQbesqXbh
> wbkcIn+mmnfhLDaHOGunYqp76tscBJv/rtxJZaX5NRLp7OraCWtbjRBtiw1fJ/tl
> iJD0HRIk9zn0pqyX8GjeAyM0UR+uL1wwrvz8Ur85ASsc8pFThTP6ZMQoaEIgo9D+
> HB3XfrhiOMd5Nb2SbjG4KCRe7alpFx83nuY53YVsv+8X+Nqp4Ndi7ch2Ni3jxxHf
> R7qVJYsMp/l72CNb6KiT85sb6PwQyeVdvU78cXKjkIKDirskGgQIEW2OvK+ZXC3B
> Aj4I+AMFXEKje8ITfW3/s/v+UNvVTNZHYC5NPZ6o50+YJFDoiwb0mpQMdUredWZk
> nT2cYMgyPQA/XKN9w5vUCNbTebPG/AA7yCthXbOrHn9Xl+kICkXRjjl9fHRUs55Q
> wgPqz0CFXPKaE+JFt/NABJzdSrki1y587GHsOb7hKFiQwS8DHU8WOMXkR3BGKEtN
> q0gebcqKvVnjRwLLsBvB0h3uI/yifgBTp8G8/+tZ0WuNdongTe+yPzchxuRjgx10
> e70xtBjgsyCQGRB3CPsgR2UelQOtAEt8ZyYwyPF5sQYOvQg1xjcYp87FqfqflSTE
> 6aQIMkXhKjKazmc/ew9F
> =Ji5Z
> -END PGP SIGNATURE-
> 
> --
> 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/20190211133426.GV10973%40konk.org.
> 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/5c6a6c98.1c69fb81.eb4fb.5c2cSMTPIN_ADDED_MISSING%40gmr-mx.google.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 

RE: Re: Composite Primary / Foreign Key support

2019-02-18 Thread Matthew Pava
"As your requirement is read-only if the data is static you could to create a 
second database, with all the PK of the legacy database, and
then as single Pk field to that table, and access everything through a view of 
a join the two tables."

I had such a requirement, and I created a View in PostgreSQL in the same 
database.  The pk field I created was just a Window function for the current 
row in the data set.  Since I didn't need that anyway, I could safely ignore 
it.  Since it was a truly read-only model, I didn't need to worry about the 
composite key.

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Roger Gammans
Sent: Monday, February 18, 2019 11:30 AM
To: django-users@googlegroups.com
Subject: Re: Re: Composite Primary / Foreign Key support

Lance,

I can't speak for the core team, only inform you based on what I've
seen here and in other projects.

I suspect if there was a significant need across a number of users,
then enough work could be done by those that needed it and as long as
it was 
1) fully functional, 
2) had clean good code 
3) the people who wrote where going to stay within the
community to support it 

Then there is a chance a set of code written might get merged, I don't
however thing there is sufficient interest from the core team for them
to do the work themselves.

Those requirements are quite a high bar, I started on some code to do
this, for a project a few years ago and got a limited set of composite
key functionality working in my own tree, which was just about enough
for the project I was working on. So I do have some understanding of
what is needed, and how intrusive and can get.

My code was fine for reading and writing, but you couldn't use
ForeignKey Fields to traverse composite key relationships. Which has a
surprising number of corner cases. This was for Django 1.8 and isn't
compatible with later versions (unfortunately). On the other hand some
of the code changes in the ORM point at a better approach, than we
took.

So it possible, but someone will need to invest some time into it.


The only immediately helpfuly ideas I have are;
As your requirement is read-only if the data is static you could to create a 
second database, with all the PK of the legacy database, and
then as single Pk field to that table, and access everything through a view of 
a join the two tables. 

Of course if another app is adding rows then you are a bit stuck, but if you 
absolutely can't add a autonumber field to use as a fake PK, then there is not 
a lot you can do. I've started adding single PK autonumber fields to legacy 
databases now when I get this issue, and
making the old PK into a unique index. So far that has working and hasn't 
broken my legacy apps.

If those are no good, either you can't use django or you going to need to 
invest in understanding the ORMs internals.

HTH,

-- 
Roger Gammans 
Gamma Science


On Mon, 2019-02-18 at 08:26 +, 'Ellinghaus, Lance J' via Django
users wrote:
> 
> ONCONFIDENTIAL // EXTERNAL
> So, basically, Django will not be supporting Composite Primary Keys
> in the future?
> 
> Lance
> 
> -Original Message-
> From: django-users@googlegroups.com 
> On Behalf Of Michal Petrucha
> Sent: Monday, February 11, 2019 8:34 AM
> To: Django users 
> Subject: [External] Re: Composite Primary / Foreign Key support
> 
> NONCONFIDENTIAL // EXTERNAL
> 
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA512
> 
> On Mon, Feb 11, 2019 at 01:08:41AM -0800, 'Lance Ellinghaus' via
> Django users wrote:
> > I have seen references to people adding the support of composite 
> > primary keys to Django for years, but it does not look like it has
> been added.
> >
> > I have a number of legacy databases that I cannot add fields to
> but 
> > need to be able to be queried through Django. They are read-only
> tables.
> > A number of the tables are also related through Composite Foreign
> Keys 
> > and I have seen some addons but not sure what is fully supported.
> >
> > I am trying to use Django 2.1.5.
> >
> > Any help or ideas would be appreciated, and saying  "Add a field
> to 
> > your tables" is not an option.
> >
> > Thank you.
> 
> Hi Lance,
> 
> I haven't been on top of this in recent years, but let me try.
> 
> When it comes to just composite primary keys, as long as you only
> need read access, you might be able to get away with marking an
> arbitrary field as the primary key. Using a non-unique field as the
> primary key would make any writes to the database dangerous, but
> that's not your case here. However, you also lose the invariant that
> filtering on the “pk” field alias will match at most one row, which
> means the admin would probably be off the table, too – since that
> assumes the “pk” is, in fact, unique, and the same holds for any
> other package that makes use of “pk”. You should still be okay in
> your own code, though.
> 
> For composite foreign keys, 

Re: Re: Composite Primary / Foreign Key support

2019-02-18 Thread Roger Gammans
Lance,

I can't speak for the core team, only inform you based on what I've
seen here and in other projects.

I suspect if there was a significant need across a number of users,
then enough work could be done by those that needed it and as long as
it was 
1) fully functional, 
2) had clean good code 
3) the people who wrote where going to stay within the
community to support it 

Then there is a chance a set of code written might get merged, I don't
however thing there is sufficient interest from the core team for them
to do the work themselves.

Those requirements are quite a high bar, I started on some code to do
this, for a project a few years ago and got a limited set of composite
key functionality working in my own tree, which was just about enough
for the project I was working on. So I do have some understanding of
what is needed, and how intrusive and can get.

My code was fine for reading and writing, but you couldn't use
ForeignKey Fields to traverse composite key relationships. Which has a
surprising number of corner cases. This was for Django 1.8 and isn't
compatible with later versions (unfortunately). On the other hand some
of the code changes in the ORM point at a better approach, than we
took.

So it possible, but someone will need to invest some time into it.


The only immediately helpfuly ideas I have are;
As your requirement is read-only if the data is static you could to create a 
second database, with all the PK of the legacy database, and
then as single Pk field to that table, and access everything through a view of 
a join the two tables. 

Of course if another app is adding rows then you are a bit stuck, but if you 
absolutely can't add a autonumber field to use as a fake PK, then there is not 
a lot you can do. I've started adding single PK autonumber fields to legacy 
databases now when I get this issue, and
making the old PK into a unique index. So far that has working and hasn't 
broken my legacy apps.

If those are no good, either you can't use django or you going to need to 
invest in understanding the ORMs internals.

HTH,

-- 
Roger Gammans 
Gamma Science


On Mon, 2019-02-18 at 08:26 +, 'Ellinghaus, Lance J' via Django
users wrote:
> 
> ONCONFIDENTIAL // EXTERNAL
> So, basically, Django will not be supporting Composite Primary Keys
> in the future?
> 
> Lance
> 
> -Original Message-
> From: django-users@googlegroups.com 
> On Behalf Of Michal Petrucha
> Sent: Monday, February 11, 2019 8:34 AM
> To: Django users 
> Subject: [External] Re: Composite Primary / Foreign Key support
> 
> NONCONFIDENTIAL // EXTERNAL
> 
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA512
> 
> On Mon, Feb 11, 2019 at 01:08:41AM -0800, 'Lance Ellinghaus' via
> Django users wrote:
> > I have seen references to people adding the support of composite 
> > primary keys to Django for years, but it does not look like it has
> been added.
> >
> > I have a number of legacy databases that I cannot add fields to
> but 
> > need to be able to be queried through Django. They are read-only
> tables.
> > A number of the tables are also related through Composite Foreign
> Keys 
> > and I have seen some addons but not sure what is fully supported.
> >
> > I am trying to use Django 2.1.5.
> >
> > Any help or ideas would be appreciated, and saying  "Add a field
> to 
> > your tables" is not an option.
> >
> > Thank you.
> 
> Hi Lance,
> 
> I haven't been on top of this in recent years, but let me try.
> 
> When it comes to just composite primary keys, as long as you only
> need read access, you might be able to get away with marking an
> arbitrary field as the primary key. Using a non-unique field as the
> primary key would make any writes to the database dangerous, but
> that's not your case here. However, you also lose the invariant that
> filtering on the “pk” field alias will match at most one row, which
> means the admin would probably be off the table, too – since that
> assumes the “pk” is, in fact, unique, and the same holds for any
> other package that makes use of “pk”. You should still be okay in
> your own code, though.
> 
> For composite foreign keys, there is nowadays a private, undocumented
> API, ForeignObject, which is what ForeignKey builds on. The general
> ForeignObject lets you specify multiple fields that make up the
> relation, you should be able to find some examples in the test suite
> (there is a foreign_object package in there). Keep in mind that this
> is an internal API, so it might change without warning.
> 
> Good luck,
> 
> Michal
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1
> 
> iQIcBAEBCgAGBQJcYXniAAoJEHA7T/IPM/kl8EAP/Rzaxqe0bDO6vkxb4/Mmmj5S
> 62t6Cfm3VqqK6NxYjRXG904jKwDI4HMH1SAs5fdVMh9vf+VBj/S5bcIpQbesqXbh
> wbkcIn+mmnfhLDaHOGunYqp76tscBJv/rtxJZaX5NRLp7OraCWtbjRBtiw1fJ/tl
> iJD0HRIk9zn0pqyX8GjeAyM0UR+uL1wwrvz8Ur85ASsc8pFThTP6ZMQoaEIgo9D+
> HB3XfrhiOMd5Nb2SbjG4KCRe7alpFx83nuY53YVsv+8X+Nqp4Ndi7ch2Ni3jxxHf
> 

Re: Django ignoring Create_DB setting on test

2019-02-18 Thread Carl Marshall
I'll note that "CREATE_DB" is slightly misleading, and would be more 
accurately called "CREATE_SEPARATE_TEST_DB_IN_ORACLE".

The error I'm getting is somewhat misleading also as there's nothing wrong 
with the ALWAYS keyword, the problem is that the test script is trying to 
create a table in a database I thought it had been told not to create 
anything in. Instead it is calling `'CREATE TABLE "DJANGO_MIGRATIONS" ("ID" 
NUMBER(11) GENERATED BY DEFAULT ON NULL AS IDENTITY NOT NULL PRIMARY KEY, 
"APP" NVARCHAR2(255) NULL, "NAME" NVARCHAR2(255) NULL, "APPLIED" TIMESTAMP 
NOT NULL)'` and then rightly falling over because this is a READ-ONLY DB.

The ability to tell Django that a database is Read-Only would be a greatly 
appreciated feature!

I'm continuing to try and work this issue through though if anyone has 
solve this (or similar), please tell me how? :)

-- 
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/3305bdbd-f8cd-4ea1-b883-48c62191efc0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Too many SQL variable

2019-02-18 Thread HEMENDRA SINGH HADA
Hi,

Could you give me some quick fix, I am using django currently, or could be 
please suggest me how to take the parent table data with prefetch related 
filter. 

Thanks 

On Monday, February 18, 2019 at 6:21:33 PM UTC+5:30, Sebastian Henschel 
wrote:
>
> Heya, 
>
> Am 18.02.19 um 10:52 schrieb HEMENDRA SINGH HADA: 
>
> > In my current project we are using sqlite3, When I am fetching data from 
> > sqlite3 db tables and counting the query-set length it is giving me 
> error 
> > "Too many SQL query" when the length is more than 999. till 999 its 
> working 
> > fine, Please suggest some quick fix for this, 
>
> The first questions which comes to my mind is, if you can rework your 
> queries? 
> Otherwise, i am not using sqlite3, but just found this, from 
> https://www.sqlite.org/limits.html : 
>
> - 
>
> Maximum Number Of Host Parameters In A Single SQL Statement 
>
> A host parameter is a place-holder in an SQL statement that is filled in 
> using one of the sqlite3_bind_() interfaces. Many SQL programmers 
> are familiar with using a question mark ("?") as a host parameter. 
> SQLite also supports named host parameters prefaced by ":", "$", or "@" 
> and numbered host parameters of the form "?123". 
>
> Each host parameter in an SQLite statement is assigned a number. The 
> numbers normally begin with 1 and increase by one with each new 
> parameter. However, when the "?123" form is used, the host parameter 
> number is the number that follows the question mark. 
>
> SQLite allocates space to hold all host parameters between 1 and the 
> largest host parameter number used. Hence, an SQL statement that 
> contains a host parameter like ?10 would require gigabytes of 
> storage. This could easily overwhelm the resources of the host machine. 
> To prevent excessive memory allocations, the maximum value of a host 
> parameter number is SQLITE_MAX_VARIABLE_NUMBER, which defaults to 999. 
>
> The maximum host parameter number can be lowered at run-time using the 
> sqlite3_limit(db,SQLITE_LIMIT_VARIABLE_NUMBER,size) interface. 
>
> --- 
>
> Maybe you can put a call to this interface into a startup script 
> somewhere? 
>
> Cheers, 
> -- 
> Sebastian Henschel 
> Softwareentwickler Passivhaus Institut 
> http://passiv.de 
>
>

-- 
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/72462981-45e8-410c-ace7-1af9fd978d19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django ignoring Create_DB setting on test

2019-02-18 Thread Carl Marshall
Hi all,

I think I've found a bug here - or certainly I have some behaviour that I 
don't expect and don't want.

My django (2.1.7) project is providing a query/read interface to some 
existing legacy databases. These are Oracle based (and that brings its own 
challenges, as they're not current Oracle either) and are only available 
via a read_only user account. To handle this I've had to duplicate and 
modify the default django.db.backends.oracle package [1] and create my own 
that reverts some of the changes made in django 2.0 back to 1.11 
equivalents which are then more compatible with the Oracle version I'm 
working against. This in the main works fine. However, problems start when 
we get to trying to run the Django test command.

Based on https://docs.djangoproject.com/en/2.1/ref/settings/#test, 
specifically:

"""
CREATE_DB¶

Default: True

This is an Oracle-specific setting.

If it is set to False, the test tablespaces won’t be automatically created 
at the beginning of the tests or dropped at the end.
"""

... I have set this to False (and confirmed this is being picked up 
correctly), and naively assumed this would do what it says. Unfortunately 
this doesn't seem to be the case as the test runner is still trying to 
create a test database for this secondary database (the default database 
for the project is an sqlite db). More unfortunately, because of what looks 
like Oracle incompatibilities combined with the attempt to create the test 
database in the face of this setting, is failing because of bad syntax [2]

I'm still trying to dig into where this is all falling over at, but what 
I'd expect here (and ideally want) is that Test runs, but it only creates a 
test_database for the default database defined in settings, and ignores the 
read-only secondary databases defined. Suggestions to create my own 
DiscoverRunner for the test are looking to be moot, as the issue isn't that 
I don't want a database created at all, it's that I don't want specific 
databases to be created during test cycles and that doesn't appear to be 
something in DiscoverRunner, but in other sub modules elsewhere in the code 
(and more and more looking like it's in the db.backends.vendor type 
modules).

Anyone got any insights they can offer here please?

E.g.: There are no migrations in any of the projects apps, so why are we 
seeing db/migrations/ in the stack trace for this fault, and for this 
secondary database?

Thanks
Carl


*Footnotes*

1. Most of this new/duplicated db backend is identical to the Django 2.1.7 
package, with the following changes:
*base.py*
 74: vendor = 'cerner_oracle'
 75: display_name = 'Cerner Oracle 11g'
197: return '{0}/{1}@{2}'.format(self.settings_dict['USER'], 
self.settings_dict['PASSWORD'], self._dsn())
These handle niceties like not being the default Oracle name, and fixes an 
issue with the connection string that otherwise stops me from getting any 
database connection.

*introspection.py*
 - Modifications to the queries to point at tables that can be accessed 
such as "ALL_TABS" rather than "USER_TABS" as the user account is not the 
db creator, and thus doesn't have any tables against it in USER_* tables. 
The upshot of these changes is that I've been able to use the python 
manage.py inspectdb command to pull out django model classes from the table 
structures as we'd like.

2.  user$ python manage.py test  OUTPUTS -->

Settings loading from local.py. env file being read=True
Creating test database for alias 'default'...
Creating test database for alias 'cerner_dev'...
Traceback (most recent call last):
  File 
"/Users/carl/.virtualenvs/diakonia-internal/lib/python3.7/site-packages/django/db/backends/utils.py",
 
line 83, in _execute
return self.cursor.execute(sql)
  File 
"/Users/carl/Projects/diakonia-internal/diakonia-internal-repo/diakonia/atlas/db/backends/cerner/base.py",
 
line 507, in execute
return self.cursor.execute(query, self._param_generator(params))
cx_Oracle.DatabaseError: ORA-02000: missing ALWAYS keyword

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File 
"/Users/carl/.virtualenvs/diakonia-internal/lib/python3.7/site-packages/django/db/migrations/recorder.py",
 
line 55, in ensure_schema
editor.create_model(self.Migration)
  File 
"/Users/carl/.virtualenvs/diakonia-internal/lib/python3.7/site-packages/django/db/backends/base/schema.py",
 
line 312, in create_model
self.execute(sql, params or None)
  File 
"/Users/carl/.virtualenvs/diakonia-internal/lib/python3.7/site-packages/django/db/backends/base/schema.py",
 
line 133, in execute
cursor.execute(sql, params)
  File 
"/Users/carl/.virtualenvs/diakonia-internal/lib/python3.7/site-packages/django/db/backends/utils.py",
 
line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, 
executor=self._execute)
  File 

ajouter plusieurs contextes dans un même template

2019-02-18 Thread abdouramane mahamane
Bonjour 

J'essaye d'afficher plusieurs resultats de ma views.py dans un template.
Mais django ne me le permet pas ,puisque à chaque url correspond un view.
J'ai essayé de faire 2 block content dans ma base mais sans résultat.

-- 
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/20c6001b-89f2-4db2-8e21-2a8f76473ab5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


templates and Views

2019-02-18 Thread abdouramane mahamane
I'm trying to show in one template .html multiple results of  my views.py 
class.
But when i add an other {%block content2 %} in my base.html, i have an 
error.
Because i have the same url 
path('partenaire/', views.OffrePListView.as_view(), name='offreListP'),
path('partenaire/', views.BaseViewP.as_view(), name='showP'),

now i have this 
path('partenaire/', views.OffrePListView.as_view(), name='offreListP'),
path('partenaire/show', views.BaseViewP.as_view(), name='showP'),

I want to show many things in one template by using many "contexts".

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/8ce80905-5986-4d91-9567-7377a5cce7b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Too many SQL variable

2019-02-18 Thread Sebastian Henschel
Heya,

Am 18.02.19 um 10:52 schrieb HEMENDRA SINGH HADA:

> In my current project we are using sqlite3, When I am fetching data from 
> sqlite3 db tables and counting the query-set length it is giving me error 
> "Too many SQL query" when the length is more than 999. till 999 its working 
> fine, Please suggest some quick fix for this,

The first questions which comes to my mind is, if you can rework your
queries?
Otherwise, i am not using sqlite3, but just found this, from
https://www.sqlite.org/limits.html :

-

Maximum Number Of Host Parameters In A Single SQL Statement

A host parameter is a place-holder in an SQL statement that is filled in
using one of the sqlite3_bind_() interfaces. Many SQL programmers
are familiar with using a question mark ("?") as a host parameter.
SQLite also supports named host parameters prefaced by ":", "$", or "@"
and numbered host parameters of the form "?123".

Each host parameter in an SQLite statement is assigned a number. The
numbers normally begin with 1 and increase by one with each new
parameter. However, when the "?123" form is used, the host parameter
number is the number that follows the question mark.

SQLite allocates space to hold all host parameters between 1 and the
largest host parameter number used. Hence, an SQL statement that
contains a host parameter like ?10 would require gigabytes of
storage. This could easily overwhelm the resources of the host machine.
To prevent excessive memory allocations, the maximum value of a host
parameter number is SQLITE_MAX_VARIABLE_NUMBER, which defaults to 999.

The maximum host parameter number can be lowered at run-time using the
sqlite3_limit(db,SQLITE_LIMIT_VARIABLE_NUMBER,size) interface.

---

Maybe you can put a call to this interface into a startup script somewhere?

Cheers,
-- 
Sebastian Henschel
Softwareentwickler Passivhaus Institut
http://passiv.de

-- 
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/09489c79-c96d-3c58-954a-564d8afb63c6%40passiv.de.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: Why use CustomUserManager.create_user and not CustomUserManager.create?

2019-02-18 Thread Đảng Nguyễn Văn
Vào 1:05, Th 2, 18 thg 2, 2019 Maarten Nieber  Hi,
>
> the Django guidelines tell us to implement CustomUserManager.create_user.
> However, this seems to introduce some ambiguity between
> CustomUserManager.create_user and CustomUserManager.create, since both
> these methods can be expected to create a User. In fact,
> it would be easy to accidentically call the wrong method from source code.
>
> Is there any reason why the create_user function exists at all? Why
> doesn't Django tell us to override CustomUserManager.create?
>
> Or alternatively, I could imagine that Django could have a hook function
> that is called by CustomUserManager.create, where the hook can be used
> to implemented custom behaviour (so that at least we have only 1 function
> to create users). Would this be a better design? Or is the current
> design the correct one, and am I missing something? (in that case, please
> elaborate)
>
> Best regards,
> Maarten
>
>
> --
> 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/b934b1a4-a295-4e83-be9c-b787785e5fc6%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/CAHRrzoy3numck3Wg4Q_fepJ5PAdOtVqrTLL48ieCo8iv%2Bg%3DtbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Too many SQL variable

2019-02-18 Thread HEMENDRA SINGH HADA
Hi All,
In my current project we are using sqlite3, When I am fetching data from 
sqlite3 db tables and counting the query-set length it is giving me error 
"Too many SQL query" when the length is more than 999. till 999 its working 
fine, Please suggest some quick fix for this,

Thanks in Advance 

-- 
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/11911c44-ea93-443e-87aa-05e34b0dcc08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Working with pk arguments within an included URL

2019-02-18 Thread Gavin Boyle
Perfect Simon. I’ll give it a go.

Appreciate your help.

Gavin

On Mon, 18 Feb 2019 at 08:10, Simon A  wrote:

> Hi Gavin,
>
> Please see this one.
> https://docs.djangoproject.com/en/2.1/topics/http/sessions/. It first
> needs to be setup in your settings.py.
>
> Basically, this is just a field in the database that gets retrieved
> whenever you want.
>
> # set a session variable
> self.request.session['key'] = 'value'
>
> # get a session variable
> self.request.session.get('key', None)
>
> On Mon, Feb 18, 2019 at 3:10 PM Gavin Boyle 
> wrote:
>
>> Hi Simon,
>>
>> That’s a great idea, I’ve only ever worked with built in sessions for
>> logging in. Would you have a link to some documentation or an example that
>> would help me as I’m relatively new to Django and this has been holding me
>> back months now.
>>
>> Thanks
>>
>> Gavin
>>
>> On Mon, 18 Feb 2019 at 04:11, Simon A  wrote:
>>
>>> I think I had a similar scenario a few weeks ago. One option that you
>>> have is to store the originally selected PK to the session object. Whenever
>>> you load a page, for you can retrieve the PK from the session object. Most
>>> likely you'll do this on the get_queryset function
>>>
>>>
>>> On Sunday, February 17, 2019 at 8:24:53 PM UTC+8, GavinB841 wrote:

 Hi,

 To briefly explained:

- I have a main site which provides links to multiple sports club
pages.
- Currently once clicked it opens the club home page and displays
information based on that club by passing in the pk.
- I then have many other pages associated to the clubs. e.g. Teams,
Player Registration, Shop etc.
- But when I click on the navbar for example "Player Registration"
I have no idea how to continue the URL with the originally selected PK 
 and
how to use that PK in the view.


 ***Current I have these pages working off the authenticated user but
 realistically I want it working off the originally selected club***

 I am not sure how to write the view to allow for this to work and then
 pass the pk argument into the nav bar url simiarlary how I did it on the
 main site:

 


 Would really appreciate any help been stuck on this for a few months
 now.

 Below is an example of the Clubs Teams I need this to work for:

 *Urls.py:*

 urlpatterns = [
 path('', views.club_home, name='club_home'),
 path('/', include([
 path('home/', views.club_home, name='club_home_with_pk'),
 path('teams/', views.TeamInfo.as_view(), name='teams'),
 ])),


 *Nav bar for club pages:*

 Home
 Team
 Pitches
 Memberships



 *Views.py*


 def club_home(request, pk=None):
 if pk:
 club = ClubInfo.objects.filter(pk=pk)
 club_posts = ClubPosts.objects.filter(club_id=club[0])
 elif request.user.is_authenticated:
 club = ClubInfo.objects.filter(user=request.user)
 club_posts = ClubPosts.objects.filter(club_id=club[0])
 # photo = model.club_logo.ImageField(storage=profile_pics)
 args = {'club': club,
 'club_posts': club_posts
 }
 return render(request, 'club_home_page.html', args)


 class TeamInfo(APIView):
 renderer_classes = [TemplateHTMLRenderer]
 template_name = 'teams.html'

 def get(self, request):
 form = TeamForm()
 user = ClubInfo.objects.filter(user=request.user).first()
 teams = Team.objects.filter(club_id=user.pk)
 return Response({'form': form,
  'teams': teams,
  })

 def post(self, request):
 form = TeamForm(data=request.data)
 user = ClubInfo.objects.filter(user=request.user).first()
 teams = Team.objects.filter(club_id=user.pk)
 if form.is_valid():
 form.save()
 return Response({'form': form,
  'teams': teams
  })



 --
>>> 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/KsvZHK1z6BI/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/c508e2ee-d73a-4a02-923d-d033e467efe3%40googlegroups.com
>>> 

RE: Re: Composite Primary / Foreign Key support

2019-02-18 Thread 'Ellinghaus, Lance J' via Django users
NONCONFIDENTIAL // EXTERNAL
So, basically, Django will not be supporting Composite Primary Keys in the 
future?

Lance

-Original Message-
From: django-users@googlegroups.com  On Behalf 
Of Michal Petrucha
Sent: Monday, February 11, 2019 8:34 AM
To: Django users 
Subject: [External] Re: Composite Primary / Foreign Key support

NONCONFIDENTIAL // EXTERNAL

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

On Mon, Feb 11, 2019 at 01:08:41AM -0800, 'Lance Ellinghaus' via Django users 
wrote:
> I have seen references to people adding the support of composite 
> primary keys to Django for years, but it does not look like it has been added.
>
> I have a number of legacy databases that I cannot add fields to but 
> need to be able to be queried through Django. They are read-only tables.
> A number of the tables are also related through Composite Foreign Keys 
> and I have seen some addons but not sure what is fully supported.
>
> I am trying to use Django 2.1.5.
>
> Any help or ideas would be appreciated, and saying  "Add a field to 
> your tables" is not an option.
>
> Thank you.

Hi Lance,

I haven't been on top of this in recent years, but let me try.

When it comes to just composite primary keys, as long as you only need read 
access, you might be able to get away with marking an arbitrary field as the 
primary key. Using a non-unique field as the primary key would make any writes 
to the database dangerous, but that's not your case here. However, you also 
lose the invariant that filtering on the “pk” field alias will match at most 
one row, which means the admin would probably be off the table, too – since 
that assumes the “pk” is, in fact, unique, and the same holds for any other 
package that makes use of “pk”. You should still be okay in your own code, 
though.

For composite foreign keys, there is nowadays a private, undocumented API, 
ForeignObject, which is what ForeignKey builds on. The general ForeignObject 
lets you specify multiple fields that make up the relation, you should be able 
to find some examples in the test suite (there is a foreign_object package in 
there). Keep in mind that this is an internal API, so it might change without 
warning.

Good luck,

Michal
-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iQIcBAEBCgAGBQJcYXniAAoJEHA7T/IPM/kl8EAP/Rzaxqe0bDO6vkxb4/Mmmj5S
62t6Cfm3VqqK6NxYjRXG904jKwDI4HMH1SAs5fdVMh9vf+VBj/S5bcIpQbesqXbh
wbkcIn+mmnfhLDaHOGunYqp76tscBJv/rtxJZaX5NRLp7OraCWtbjRBtiw1fJ/tl
iJD0HRIk9zn0pqyX8GjeAyM0UR+uL1wwrvz8Ur85ASsc8pFThTP6ZMQoaEIgo9D+
HB3XfrhiOMd5Nb2SbjG4KCRe7alpFx83nuY53YVsv+8X+Nqp4Ndi7ch2Ni3jxxHf
R7qVJYsMp/l72CNb6KiT85sb6PwQyeVdvU78cXKjkIKDirskGgQIEW2OvK+ZXC3B
Aj4I+AMFXEKje8ITfW3/s/v+UNvVTNZHYC5NPZ6o50+YJFDoiwb0mpQMdUredWZk
nT2cYMgyPQA/XKN9w5vUCNbTebPG/AA7yCthXbOrHn9Xl+kICkXRjjl9fHRUs55Q
wgPqz0CFXPKaE+JFt/NABJzdSrki1y587GHsOb7hKFiQwS8DHU8WOMXkR3BGKEtN
q0gebcqKvVnjRwLLsBvB0h3uI/yifgBTp8G8/+tZ0WuNdongTe+yPzchxuRjgx10
e70xtBjgsyCQGRB3CPsgR2UelQOtAEt8ZyYwyPF5sQYOvQg1xjcYp87FqfqflSTE
6aQIMkXhKjKazmc/ew9F
=Ji5Z
-END PGP SIGNATURE-

--
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/20190211133426.GV10973%40konk.org.
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/5c6a6c98.1c69fb81.eb4fb.5c2cSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
For more options, visit https://groups.google.com/d/optout.


Re: REG: Why my django email settings not sending email notifications?

2019-02-18 Thread Siddharth Tamang
if you have MFA enabled on your gmail, you may have to disable it

On Mon, Feb 18, 2019 at 1:08 PM Onkar Narkar 
wrote:

>
> Hi Amitesh,
>
>  Are you getting some error like this:
> smtplib.SMTPAuthenticationError: (534, b'5.7.9 Application-specific
> password required. Learn more at\n5.7.9
> https://support.google.com/mail/?p=InvalidSecondFactor 128sm18480521pfx.7
> - gsmtp')
>
> If this is the case, you need to specify *application* *specific password*
> instead of your nornal in gmail password.
>
> On Sunday, 17 February 2019 14:49:35 UTC+5:30, Amitesh Sahay wrote:
>>
>> I have created a registration page that sends an email notification on
>> successful registration. I do have my email notification in place. But it
>> doesn't seem to be working, neither it is throwing any error. Below is the
>> code snippet.
>> views.py
>>
>> def register(request):
>> validators = [MinimumLengthValidator, NumberValidator, 
>> UppercaseValidator]
>> if request.method == 'POST':
>> first_name = request.POST['first_name']
>> last_name = request.POST['last_name']
>> email = request.POST['email']
>> username = request.POST['username']
>> password = request.POST['password']
>> try:
>> for validator in validators:
>> validator().validate(password)
>> except ValueError as e:
>> messages.error(request, str(e))
>> return redirect('register')
>> password2 = request.POST['password2']
>>
>> # check if the password match
>> if password == password2:
>>
>> if User.objects.filter(username=username).exists():
>> messages.error(request, 'username already exist')
>> return redirect('register')
>> else:
>> if User.objects.filter(email=email).exists():
>> messages.error(request, 'Registration Failed - Try 
>> different email address')
>> return redirect('register')
>> else:
>> user = User.objects.create_user(username=username, 
>> password=password, email=email,
>> first_name=first_name, 
>> last_name=last_name)
>> user.save()
>> messages.success(request, 'Registration complete, please 
>> proceed to login')
>> return redirect('register')
>> else:
>> messages.error(request, 'password dose not match')
>> return redirect('register')
>> else:
>> return render(request, 'ACCOUNTS/register.html')
>>
>> def ThankYou(request, register):
>> if request.method == 'POST':
>> if register.is_valid():
>> save_it = register.save(commit=False)
>> save_it.save()
>> subject = 'Registration successful'
>> message = 'Thank you for registration, please continue with 
>> the login'
>> from_email = settings.EMAIL_HOST_USER
>> to_list = [save_it.email, settings.EMAIL_HOST_USER]
>> try:
>> send_mail(
>> subject,
>> message,
>> from_email,
>> [to_list],
>> fail_silently=False,
>> )
>> except ValueError:
>> return HttpResponse('Invalid header found.')
>> else:
>> messages.success(request, 'thank you ')
>> return redirect('register')
>> else:
>> return redirect('index')
>>
>> Below is my settings.py
>>
>> EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
>> EMAIL_USE_TLS = False
>> EMAIL_HOST = 'smtp.gmail.com'
>> EMAIL_PORT = 587
>> EMAIL_HOST_USER = 'ami@gmail.com'
>> EMAIL_HOST_PASSWORD = '123'
>> DEFAULT_FROM_EMAIL = 'ami@gmail.com'
>>
>> I have gone through a couple of Stackoverflow posts and made some changes
>> as suggested. But they do not seem to have any effect. Below is one of the
>> link.
>>
>> Django Doesn't Send Email Notifications
>> 
>> Regards,
>> Amitesh Sahay
>> *91-750 797 8619*
>>
> --
> 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/bfc6ce59-182a-421f-826c-2e322d4b20a0%40googlegroups.com
> 
> .
> For more options, 

Re: Working with pk arguments within an included URL

2019-02-18 Thread Simon A
Hi Gavin,

Please see this one.
https://docs.djangoproject.com/en/2.1/topics/http/sessions/. It first needs
to be setup in your settings.py.

Basically, this is just a field in the database that gets retrieved
whenever you want.

# set a session variable
self.request.session['key'] = 'value'

# get a session variable
self.request.session.get('key', None)

On Mon, Feb 18, 2019 at 3:10 PM Gavin Boyle 
wrote:

> Hi Simon,
>
> That’s a great idea, I’ve only ever worked with built in sessions for
> logging in. Would you have a link to some documentation or an example that
> would help me as I’m relatively new to Django and this has been holding me
> back months now.
>
> Thanks
>
> Gavin
>
> On Mon, 18 Feb 2019 at 04:11, Simon A  wrote:
>
>> I think I had a similar scenario a few weeks ago. One option that you
>> have is to store the originally selected PK to the session object. Whenever
>> you load a page, for you can retrieve the PK from the session object. Most
>> likely you'll do this on the get_queryset function
>>
>>
>> On Sunday, February 17, 2019 at 8:24:53 PM UTC+8, GavinB841 wrote:
>>>
>>> Hi,
>>>
>>> To briefly explained:
>>>
>>>- I have a main site which provides links to multiple sports club
>>>pages.
>>>- Currently once clicked it opens the club home page and displays
>>>information based on that club by passing in the pk.
>>>- I then have many other pages associated to the clubs. e.g. Teams,
>>>Player Registration, Shop etc.
>>>- But when I click on the navbar for example "Player Registration" I
>>>have no idea how to continue the URL with the originally selected PK and
>>>how to use that PK in the view.
>>>
>>>
>>> ***Current I have these pages working off the authenticated user but
>>> realistically I want it working off the originally selected club***
>>>
>>> I am not sure how to write the view to allow for this to work and then
>>> pass the pk argument into the nav bar url simiarlary how I did it on the
>>> main site:
>>>
>>> 
>>>
>>>
>>> Would really appreciate any help been stuck on this for a few months
>>> now.
>>>
>>> Below is an example of the Clubs Teams I need this to work for:
>>>
>>> *Urls.py:*
>>>
>>> urlpatterns = [
>>> path('', views.club_home, name='club_home'),
>>> path('/', include([
>>> path('home/', views.club_home, name='club_home_with_pk'),
>>> path('teams/', views.TeamInfo.as_view(), name='teams'),
>>> ])),
>>>
>>>
>>> *Nav bar for club pages:*
>>>
>>> Home
>>> Team
>>> Pitches
>>> Memberships
>>>
>>>
>>>
>>> *Views.py*
>>>
>>>
>>> def club_home(request, pk=None):
>>> if pk:
>>> club = ClubInfo.objects.filter(pk=pk)
>>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>>> elif request.user.is_authenticated:
>>> club = ClubInfo.objects.filter(user=request.user)
>>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>>> # photo = model.club_logo.ImageField(storage=profile_pics)
>>> args = {'club': club,
>>> 'club_posts': club_posts
>>> }
>>> return render(request, 'club_home_page.html', args)
>>>
>>>
>>> class TeamInfo(APIView):
>>> renderer_classes = [TemplateHTMLRenderer]
>>> template_name = 'teams.html'
>>>
>>> def get(self, request):
>>> form = TeamForm()
>>> user = ClubInfo.objects.filter(user=request.user).first()
>>> teams = Team.objects.filter(club_id=user.pk)
>>> return Response({'form': form,
>>>  'teams': teams,
>>>  })
>>>
>>> def post(self, request):
>>> form = TeamForm(data=request.data)
>>> user = ClubInfo.objects.filter(user=request.user).first()
>>> teams = Team.objects.filter(club_id=user.pk)
>>> if form.is_valid():
>>> form.save()
>>> return Response({'form': form,
>>>  'teams': teams
>>>  })
>>>
>>>
>>>
>>> --
>> 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/KsvZHK1z6BI/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/c508e2ee-d73a-4a02-923d-d033e467efe3%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> *Séanadh Ríomhphoist/Email DisclaimerTá an ríomhphost seo agus aon chomhad
> a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus sin amháin
> é. Is