RE: How to store a key to a something that can be either a person or an organization?

2017-10-20 Thread Matthew Pava
In my project, I have a contacts model.
I have separate models, such as Person, Institution, Supplier, or Shipper that 
all have a foreign key to contacts.
So it looks like you’re doing it the way that I would do it.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Jani Tiainen
Sent: Friday, October 20, 2017 2:24 PM
To: django-users@googlegroups.com
Subject: Re: How to store a key to a something that can be either a person or 
an organization?

I would be a bit cautious with generic foreignkeys since they don’t provide 
database integrity checks.

IOW, you can break your data very easily.

On 20 Oct 2017, at 19.55, Ruben Alves 
mailto:rubenalves...@gmail.com>> wrote:

You can use Generic Key: 
https://docs.djangoproject.com/en/1.11/ref/contrib/contenttypes/



Em sexta-feira, 20 de outubro de 2017 07:59:35 UTC-2, Antonis Christofides 
escreveu:
Hello,

Two real examples that I've faced:

class MeteorologicalStation(models.Model):
...
owner = models.ForeignKey(to a person or organization)


class Document(models.Model):
...
authors = models.ManyToManyKey(to persons or organizations)

What I do is I create a superclass that I call Lentity (short for "legal
entity", despite the fact that it could refer to a group of people and is not
necessary legal) and the two subclasses Person and Organization, with
multi-table inheritance.

But since I guess that this is a relatively common problem, I was wondering
about what other people are doing.

Thanks!

Antonis

--
Antonis Christofides
http://djangodeployment.com


--
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/f1fcc861-b3f3-43dc-9bad-a2511de4da44%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/72D4C974-6300-4F06-8C80-C4E0EA9D398F%40gmail.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/c2b61c3f509448b297e9ae3ee2b7979d%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: do i always have to reload/return render a page to show the errors? if i press go back on browser, i see screens with the error message

2017-10-31 Thread Matthew Pava
Try using the @never_cache decorator on your login view.
https://docs.djangoproject.com/en/1.11/topics/http/decorators/#django.views.decorators.cache.never_cache


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of fábio andrews rocha marques
Sent: Tuesday, October 31, 2017 9:15 AM
To: Django users
Subject: Re: do i always have to reload/return render a page to show the 
errors? if i press go back on browser, i see screens with the error message

That's a great suggestion. Sure, it will help on situations where i just want 
the fields to be completed. But there are some fields that require a little 
more feedback than that. Like, if a username already exists... I check if it 
already exists using a View and checking on the database. So, after the View 
checks if the user already exists, i have to render the page again to show the 
error.

On Tuesday, October 31, 2017 at 8:37:05 AM UTC-3, Eric Pascual wrote:
Hello
Sorry or I misunderstood your problem but what about using the required field 
attribute ? It will make such controls and messages be handled directly on the 
client side.
Best regards.

Eric PASCUAL

Centre Scientifique et Technique du Bâtiment
290 route des Lucioles
06560 SOPHIA ANTIPOLIS
http://www.cstb.fr



From: django...@googlegroups.com 
[django...@googlegroups.com] on behalf of fábio andrews rocha 
marques [fabioandrews...@gmail.com]
Sent: Tuesday, October 31, 2017 00:46
To: Django users
Subject: do i always have to reload/return render a page to show the errors? if 
i press go back on browser, i see screens with the error message

Let's say i have a "register a new user" View and on this page, when the user 
forgets to inform a password or a username, i show a message to him on the same 
page saying "you forgot the password". The way i do this is by doing this(on my 
View.py in a function called cadastrarprofessor):

nomeusuario = request.POST['usuario'] #username
nomesenha = request.POST['senha'] #password
nomeemail = request.POST['email'] #email

if not nomeusuario:
return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 
'error_message': "informe um usuário", 'nomeemailcadastro':nomeemail, 
'nomesenhacadastro':nomesenha})
elif not nomesenha:
return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 
'error_message': "informe uma senha", 'nomeemailcadastro':nomeemail, 
'nomeusuariocadastro':nomeusuario})
elif not nomeemail:
return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 
'error_message': "informe um email", 'nomesenhacadastro':nomesenha,

'nomeusuariocadastro':nomeusuario})

And my template for this page(cadastro.html) is like this:

Cadastro

{% csrf_token %}
Usuário: 
{% if nomeusuariocadastro %}

{% else %}

{% endif %}


... (DO THE SAME TO SENHA/PASSWORD AND EMAIL)





{% csrf_token %}

{% if cadastrorealizadocomsucesso is True %}cadastro realizado com 
sucesso!{% endif %}
{% if error_message %}{{ error_message }}{% endif %}

So, every time the user forgets to mention a username or email or password in 
this screen, i use render to redirect the user to the same page but this time 
displaying a error_message. Let's say he did forget to fill the textfield with 
a username... he goes back to the same page and sees the error message. After 
that, let's say everything is right and he finally registers a new user, he 
sees "cadastro realizado com sucesso"(sucessfully registered new user) and 
stays on the same page. But when he goes back a page(pressing "back" on the 
browser), instead of going back to the page before the cadastro.html, he goes 
back to the same page cadastro.html but displaying the error message for the 
"you forgot to mention your username". I don't want him to go back to the same 
page with error message, i want to make him go back to my main menu.
Is there a better approach to display error messages on the same page instead 
of using return render like this:
return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 
'error_message': "informe um usuário", 
'nomeemailcadastro':nomeemail,'nomesenhacadastro':nomesenha})
?


--
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/3f70cd29-9edc-4272-a27e-534ee7f1e1a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received

RE: do i always have to reload/return render a page to show the errors? if i press go back on browser, i see screens with the error message

2017-10-31 Thread Matthew Pava
> to do this, i just have to put the @never_cache on my View's method, right?

Yes.

Upon further investigation of your code, I suggest looking into Django forms 
and utilizing them.  Also, you shouldn’t need to use two forms on your log-in 
view.  The submit button should go inside the log-in form.

To get back to fixing your current code, do you have an else condition that 
always returns a render?  And, yes, you need to return an HttpResponse object 
in all of your view functions, which is returned by the render function.  It 
looks like you are always populating ‘error_message,’ which is why there is 
always an error_message rendered.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of fábio andrews rocha marques
Sent: Tuesday, October 31, 2017 11:06 AM
To: Django users
Subject: Re: do i always have to reload/return render a page to show the 
errors? if i press go back on browser, i see screens with the error message

to do this, i just have to put the @never_cache on my View's method, right? 
(after importing 'from django.views.decorators.cache import never_cache'). For 
some reason, when i did this, the page started and i already got the message 
"usuário já existe"(username already exists) and still the problem i stated 
occurred. Is it something i am doing wrong? Like, i should remover the return 
renders from my function after putting @never_cache?

On Tuesday, October 31, 2017 at 11:25:28 AM UTC-3, Matthew Pava wrote:
Try using the @never_cache decorator on your login view.
https://docs.djangoproject.com/en/1.11/topics/http/decorators/#django.views.decorators.cache.never_cache


From: django...@googlegroups.com 
[mailto:django...@googlegroups.com] On Behalf Of fábio andrews 
rocha marques
Sent: Tuesday, October 31, 2017 9:15 AM
To: Django users
Subject: Re: do i always have to reload/return render a page to show the 
errors? if i press go back on browser, i see screens with the error message

That's a great suggestion. Sure, it will help on situations where i just want 
the fields to be completed. But there are some fields that require a little 
more feedback than that. Like, if a username already exists... I check if it 
already exists using a View and checking on the database. So, after the View 
checks if the user already exists, i have to render the page again to show the 
error.

On Tuesday, October 31, 2017 at 8:37:05 AM UTC-3, Eric Pascual wrote:
Hello
Sorry or I misunderstood your problem but what about using the required field 
attribute ? It will make such controls and messages be handled directly on the 
client side.
Best regards.

Eric PASCUAL

Centre Scientifique et Technique du Bâtiment
290 route des Lucioles
06560 SOPHIA ANTIPOLIS
http://www.cstb.fr



From: django...@googlegroups.com<mailto:django...@googlegroups.com> 
[django...@googlegroups.com] on behalf of fábio andrews rocha marques 
[fabioandrews...@gmail.com]
Sent: Tuesday, October 31, 2017 00:46
To: Django users
Subject: do i always have to reload/return render a page to show the errors? if 
i press go back on browser, i see screens with the error message

Let's say i have a "register a new user" View and on this page, when the user 
forgets to inform a password or a username, i show a message to him on the same 
page saying "you forgot the password". The way i do this is by doing this(on my 
View.py in a function called cadastrarprofessor):

nomeusuario = request.POST['usuario'] #username
nomesenha = request.POST['senha'] #password
nomeemail = request.POST['email'] #email

if not nomeusuario:
return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 
'error_message': "informe um usuário", 'nomeemailcadastro':nomeemail, 
'nomesenhacadastro':nomesenha})
elif not nomesenha:
return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 
'error_message': "informe uma senha", 'nomeemailcadastro':nomeemail, 
'nomeusuariocadastro':nomeusuario})
elif not nomeemail:
return render(request,'cadastro.html',{'cadastrorealizadocomsucesso': False, 
'error_message': "informe um email", 'nomesenhacadastro':nomesenha,

'nomeusuariocadastro':nomeusuario})

And my template for this page(cadastro.html) is like this:

Cadastro

{% csrf_token %}
Usuário: 
{% if nomeusuariocadastro %}

{% else %}

{% endif %}


... (DO THE SAME TO SENHA/PASSWORD AND EMAIL)





{% csrf_token %}

{% if cadastrorealizadocomsucesso is True %}cadastro realizado com 
sucesso!{% endif %}
{% if error_message %}{{ error_message }}{% endif %}

So, every time the user forgets to mention a username or email or password in 
this screen, i use render to redirect the user to the same page 

RE: do i always have to reload/return render a page to show the errors? if i press go back on browser, i see screens with the error message

2017-10-31 Thread Matthew Pava
I had a similar issue and even tried using sessions, but I eventually found 
that never_cache worked beautifully for me.  I didn’t have to worry about 
sessions any more.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of fábio andrews rocha marques
Sent: Tuesday, October 31, 2017 12:19 PM
To: Django users
Subject: Re: do i always have to reload/return render a page to show the 
errors? if i press go back on browser, i see screens with the error message

I found this topic within stackoverflow: 
https://stackoverflow.com/questions/10906548/django-redirect-behavior-with-back-button

 that seems to me that the user was having the same problem as i am. The only 
answer i found could work was from magicTuscan, but he just said "I would save 
the last site path as a session, then retrieve via the view when the page is 
called again via the back button". I've tried to contact him but didn't get an 
answer. Is it possible to override the "browser back button" behavior on django 
using sessions?
--
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/3ad05d02-cecd-4560-9654-82d2ed1106ca%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/15cf220e045849d48d63fee8a42de578%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: do i always have to reload/return render a page to show the errors? if i press go back on browser, i see screens with the error message

2017-10-31 Thread Matthew Pava
Hmmm, yes, I have a slightly different situation then.
You might want to employ something with the query string.  Django, by default, 
uses “next” as a parameter on the Login screen.  When the user successfully 
logs in, they are redirected to the URL specified in the “next” GET parameter.  
It doesn’t address the issue of pressing the Back button, but the user may be 
discouraged from pressing the back button if they actually end up on the page 
that they were expecting to be at in the first place.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of fábio andrews rocha marques
Sent: Tuesday, October 31, 2017 1:02 PM
To: Django users
Subject: Re: do i always have to reload/return render a page to show the 
errors? if i press go back on browser, i see screens with the error message

How did you use the never_cache? Because if i just put @never_cache before the 
def of my view: def cadastrarprofessor(request):, it's like it doesn't do 
anything (i am on the login page, I go to the registration page, inform a name 
of a user that already exists, click "register", the system refreshes the page 
telling me that the user already exists and when i press the "back button" from 
the browser, it goes back to the registration page with empty fields, which is 
not what iwant. I want to go back to the login page, the page before the 
registration). Do I have to use @never_cache and remove all the return render 
from my function? What should i return instead?
On Tuesday, October 31, 2017 at 2:46:01 PM UTC-3, Matthew Pava wrote:
I had a similar issue and even tried using sessions, but I eventually found 
that never_cache worked beautifully for me.  I didn’t have to worry about 
sessions any more.

From: django...@googlegroups.com 
[mailto:django...@googlegroups.com] On Behalf Of fábio andrews 
rocha marques
Sent: Tuesday, October 31, 2017 12:19 PM
To: Django users
Subject: Re: do i always have to reload/return render a page to show the 
errors? if i press go back on browser, i see screens with the error message

I found this topic within stackoverflow: 
https://stackoverflow.com/questions/10906548/django-redirect-behavior-with-back-button

 that seems to me that the user was having the same problem as i am. The only 
answer i found could work was from magicTuscan, but he just said "I would save 
the last site path as a session, then retrieve via the view when the page is 
called again via the back button". I've tried to contact him but didn't get an 
answer. Is it possible to override the "browser back button" behavior on django 
using sessions?
--
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 djang...@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/3ad05d02-cecd-4560-9654-82d2ed1106ca%40googlegroups.com<https://groups.google.com/d/msgid/django-users/3ad05d02-cecd-4560-9654-82d2ed1106ca%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/fa86e291-ad2e-4b5a-b78a-1e98327189ce%40googlegroups.com<https://groups.google.com/d/msgid/django-users/fa86e291-ad2e-4b5a-b78a-1e98327189ce%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

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


RE: Equivalent of multi-table JOIN (another post on reverse select_related)

2017-11-06 Thread Matthew Pava
Though it doesn’t directly answer your query, you might be interested in this 
package:
https://github.com/burke-software/django-report-builder


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Samuel Abels
Sent: Monday, November 6, 2017 1:33 PM
To: Django users
Subject: Equivalent of multi-table JOIN (another post on reverse select_related)

I am working on a reporting feature that allows users for querying arbitrary 
models and fields, and present the result as a table. For example, consider the 
following object model:

Package
   |
   v
Device <- Component
   ^ ^
   | |
   | Interface <---2--- Connection
^^^
   / | \
  /  |  \
 /   |   \
  Sampling  IP   Policy

(The dash is the direction of a ForeignKey.)
To produce a report, I chose a three-step process:

1. The user interfaces returns a list of fields to be included in the report, 
such as

args = dict('Device.hostname__contains': 'localhost', 
'Package.name__icontains': 'unix', 'IP.address__contains': '192')

2. Given the list of args, find the shortest path that connects all required 
models. For the example above, the result is a tuple:

path = Device, Package, Interface, IP

3. In theory, I could now perform the following SQL request:

SELECT * FROM myapp_device d
LEFT JOIN myapp_package pa ON pa.device_id=d.id
LEFT JOIN myapp_interface ifc ON ifc.device_id=d.id
LEFT JOIN myapp_ip ip ON ip.interface_id=ifc.id;

But of course, I want to avoid the raw SQL. I considered the following options:

- Using Device.objects.select_related() does not work, because Device has a 1:n 
relation to Package (and also to Unit), which Django's select_related() does 
not support.

- Using prefetch_related() does not work, because it prefetches everything, 
which is too much in our case (>100 million rows if a user queries on all 
tables), and it does not provide us with a total of the number of rows 
selected. In practice, I want to count(*) everything for displaying a total, 
and fetch only a subset, using LIMIT.

Our tests showed that the raw SQL query with LEFT JOIN is fast enough for 
production, regardless of what fields and objects are being queried. The 
craziest query I built took about 20 seconds, which is ok for what we are 
trying to do.

Any other options?

-Samuel
--
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/ec0e2d37-9b0f-4623-8f60-c6feeef0eb9e%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/296e72112fa946b6b3f13cf52b96303d%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Equivalent of multi-table JOIN (another post on reverse select_related)

2017-11-06 Thread Matthew Pava
Maybe you are expecting too much from the user interface.  Shouldn’t you at 
least request from the user what primary object you are looking for?  Explicit 
is better than implicit.  Your example indicates that your primary object is a 
Device, but your UI dict gives no indication whatsoever that that’s what you 
want.

If you want to look for related fields in a model, check out the Model _meta 
API:
https://docs.djangoproject.com/en/1.11/ref/models/meta/

Ultimately, your Django ORM code would look like this for your example, if I 
follow your arrows correctly:
Device.objects.filter(hostname__contains= 'localhost ', 
package__name__contains= 'unix ', interface__IP__address__contains= '192')

It would seem that you want your UI to pass in the primary model and with all 
other models how they are related to the primary model.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Samuel Abels
Sent: Monday, November 6, 2017 1:59 PM
To: Django users
Subject: Re: Equivalent of multi-table JOIN (another post on reverse 
select_related)

Thanks, I have seen that and plan to use it, but for this particular feature I 
need something more tailored.

-Samuel

On Monday, November 6, 2017 at 8:56:29 PM UTC+1, Matthew Pava wrote:
Though it doesn’t directly answer your query, you might be interested in this 
package:
https://github.com/burke-software/django-report-builder


From: django...@googlegroups.com 
[mailto:django...@googlegroups.com] On Behalf Of Samuel Abels
Sent: Monday, November 6, 2017 1:33 PM
To: Django users
Subject: Equivalent of multi-table JOIN (another post on reverse select_related)

I am working on a reporting feature that allows users for querying arbitrary 
models and fields, and present the result as a table. For example, consider the 
following object model:

Package
   |
   v
Device <- Component
   ^ ^
   | |
   | Interface <---2--- Connection
^^^
   / | \
  /  |  \
 /   |   \
  Sampling  IP   Policy

(The dash is the direction of a ForeignKey.)
To produce a report, I chose a three-step process:

1. The user interfaces returns a list of fields to be included in the report, 
such as

args = dict('Device.hostname__contains': 'localhost', 
'Package.name__icontains': 'unix', 'IP.address__contains': '192')

2. Given the list of args, find the shortest path that connects all required 
models. For the example above, the result is a tuple:

path = Device, Package, Interface, IP

3. In theory, I could now perform the following SQL request:

SELECT * FROM myapp_device d
LEFT JOIN myapp_package pa ON pa.device_id=d.id<http://d.id>
LEFT JOIN myapp_interface ifc ON ifc.device_id=d.id<http://d.id>
LEFT JOIN myapp_ip ip ON ip.interface_id=ifc.id<http://ifc.id>;

But of course, I want to avoid the raw SQL. I considered the following options:

- Using Device.objects.select_related() does not work, because Device has a 1:n 
relation to Package (and also to Unit), which Django's select_related() does 
not support.

- Using prefetch_related() does not work, because it prefetches everything, 
which is too much in our case (>100 million rows if a user queries on all 
tables), and it does not provide us with a total of the number of rows 
selected. In practice, I want to count(*) everything for displaying a total, 
and fetch only a subset, using LIMIT.

Our tests showed that the raw SQL query with LEFT JOIN is fast enough for 
production, regardless of what fields and objects are being queried. The 
craziest query I built took about 20 seconds, which is ok for what we are 
trying to do.

Any other options?

-Samuel
--
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 djang...@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/ec0e2d37-9b0f-4623-8f60-c6feeef0eb9e%40googlegroups.com<https://groups.google.com/d/msgid/django-users/ec0e2d37-9b0f-4623-8f60-c6feeef0eb9e%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on 

RE: Equivalent of multi-table JOIN (another post on reverse select_related)

2017-11-06 Thread Matthew Pava
Is it really that bad?  Maybe I’m missing something in your situation.  I use 
my own custom page_queryset function.  I never got around to looking at the 
built-in Django way of doing it.  I think there is a generic view that can do 
paging.
q = Device.objects.filter(hostname__contains= 'localhost ', 
package__name__contains= 'unix ', interface__IP__address__contains= '192')
total_count = q.count()

def page_queryset(qs, page, count_per_page):
"""
:param qs: the queryset or list to slice
:param page: the current page to get records from (1-based)
:param count_per_page: how many items are part of each page
:return: a tuple: the index of the last page, the sliced queryset
"""
slice_begin = (page - 1) * count_per_page
slice_end = slice_begin + count_per_page

if type(qs) == QuerySet:
max_count = qs.count()
else:
max_count = len(qs)

slice_end = slice_end if slice_end < max_count else max_count
last_page = max_count // count_per_page + 1
return last_page, qs[slice_begin:slice_end]


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Samuel Abels
Sent: Monday, November 6, 2017 2:22 PM
To: Django users
Subject: Re: Equivalent of multi-table JOIN (another post on reverse 
select_related)



On Monday, November 6, 2017 at 9:15:09 PM UTC+1, Matthew Pava wrote:
Maybe you are expecting too much from the user interface.  Shouldn’t you at 
least request from the user what primary object you are looking for?

The primary model is always that one that is closest to "device"; step 2 of the 
process already takes this into account and returns the path in the best order, 
with the primary model being returned first.

Ultimately, your Django ORM code would look like this for your example, if I 
follow your arrows correctly:
Device.objects.filter(hostname__contains= 'localhost ', 
package__name__contains= 'unix ', interface__IP__address__contains= '192')

This would perform the right query, but would not provide me with a total. It 
would also be impossible to do paging, because slicing the result does not take 
into account that the LEFT JOIN multiplies the number of total rows.

-Samuel
--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/f1c92f41-ce59-47c5-9a82-6af38467a536%40googlegroups.com<https://groups.google.com/d/msgid/django-users/f1c92f41-ce59-47c5-9a82-6af38467a536%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

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


RE: Error in django 1.8.7 version with python 2.7.12

2017-11-10 Thread Matthew Pava
It looks like you’re running it in Python 3, not Python 2.7.12.  I would start 
looking there.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Ankush Chauhan
Sent: Friday, November 10, 2017 4:35 AM
To: Django users
Subject: Error in django 1.8.7 version with python 2.7.12

I am getting the following trackback error message when I run command(python 
manage.py runserver) on ubuntu OS:


Traceback (most recent call last):

  File "manage.py", line 10, in 

execute_from_command_line(sys.argv)

  File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", 
line 354, in execute_from_command_line

utility.execute()

  File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", 
line 303, in execute

settings.INSTALLED_APPS

.

...
--
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/6f92304a-1700-44a7-aa6b-bdcadbf81877%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/aa8b5a51a42d4f94a41d56fbe04ee961%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: [1.11] deviation between .create() and .update()

2017-11-13 Thread Matthew Pava
Are you saving the string representation of the model instance?  I would cast 
the model instance as a str in that case, i.e.  str(instance).

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Henrik Baran
Sent: Sunday, November 12, 2017 6:54 AM
To: django-users@googlegroups.com
Subject: [1.11] deviation between .create() and .update()

Hi Django users,

I observed something weird while trying to update an existing database record. 
I create new records by passing a dictionary as **kwargs to .create(). This 
dictionary includes strings, integers and model instances matching with my 
model fields. However, one model field is a CharField that can be populated 
passing a model instance. This works fine for create. But if I try to update 
this record passing the exactly same dictionary as **kwargs to .update(), 
Django raises a TypeError telling me that I cannot update that field because it 
is a CharField and I cannot pass model instances.

... so is this a bug, because it works in .create() or must I adapt my approach?


Thanks a lot for reply.
BR,
Henrik

--
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/7012f455-7483-fab4-92c3-4cf943ef1a09%40posteo.de.
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/1c86ddd84f7a4361b0623ab77f1ea482%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Form on each page problem when upgrading from Django 1.4

2017-11-13 Thread Matthew Pava
That is an interesting setup.  We just use login middleware that automatically 
redirects to the LogIn view with a next GET parameter.

In your situation, I would probably treat the form as ajax and create an ajax 
view for handling the login form processing.  Just change your action URL to 
your ajax login view url.  You would still include the form in the way you have 
and just add some Javascript to the form file.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of yakkades...@gmail.com
Sent: Sunday, November 12, 2017 11:57 AM
To: Django users
Subject: Form on each page problem when upgrading from Django 1.4

I'm in the process of upgrading a website from Django 1.4 and I'm run into a 
problem of getting my code that shows a form on almost every page migrated.  I 
eventually want to upgrade to Django 1.11 but I'm currently working on 
upgrading from Django 1.4 to Django 1.5.  I have a “request information” form 
on each page except for a few sign-up pages.

In Django 1.4 I used direct_to_template for most of the website.  I have a 
 that is inheirted by each page.  For example , 
, etc. inherit  from .  In  I load the 
right columns html with
“{% block rightColumn  %} {%include "site/rightColumn.html"%}  {%endblock%}”
and then in  I load the form's html with
“{%include "site/reqInfoForm.html"%}”.

To get the from on each page I used middleware similar to this 
http://stackoverflow.com/questions/2734055/putting-a-django-login-form-on-every-page.
  I created a class with a method “def process_view(self, request, view_func, 
view_args, view_kwargs)”.  In the method if a POST request and not one of the 
signup pages then I create a form instance from the request and if the form is 
valid then process it then redirect to thanks page, otherwise attach the form 
to the request so that I can show the errors in the form template.

This worked perfectly in Django 1.4 though it seemed like a hack.

While upgrading to Django 1.5 in the url.py I switched from 
“direct_to_template” to “TemplateView.as_view”.  Now when there is an error in 
the form (i.e., leave a required field blank), I get an error “"POST / 
HTTP/1.1" 405 0” while running with the local server.  When I did some 
research, it appears TemplateView doesn't have a POST method.

It seems one way may be to add TemplateView for each page but it seems like I 
would have to add a post method for each page(or maybe a mixin).  Any thoughts 
on this method?  I found another method using context processors but I'm not 
following it.  Also any suggestions on other ways of adding a form to almost 
all pages?
--
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/52c882b9-09d5-4b58-8234-b967785650de%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/fe308cea8d434d34add82c57a43210e4%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Download a file on Django and delete it after return

2017-11-14 Thread Matthew Pava
We can download PDFs in our project.
We start out generating the PDF on the server.  We read the contents of it into 
a variable to put it into memory.  Then we delete the file on the server (it’s 
still in memory), and the response is itself the PDF document.

I’ll share the last bit of code that we use:
with open(file_and_path, 'rb') as f:
pdf_contents = f.read()

os.remove(file_and_path)
response = HttpResponse(pdf_contents, content_type='application/pdf')
response['Content-Disposition'] = "%sfilename=%s" % ('attachment; ' if download 
else '', filename)
return response


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Ruifeng Hu
Sent: Tuesday, November 14, 2017 4:56 PM
To: Django users
Subject: Download a file on Django and delete it after return

Hi All,

I am now writing a web service which can generate a file and download it 
automatically for users, but I want to delete it after the file has been 
downloaded(after return the HttpResponse). What should I do ?

Thank You!

Ruifeng Hu


--
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/508fcace-efc8-42c0-a667-b760fec4c141%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/c1c42116948e47ed926312adf4a87853%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: How to get as result a list of all the users ordered by birthday (month day), ignoring year

2017-11-21 Thread Matthew Pava
https://docs.djangoproject.com/en/1.11/ref/models/database-functions/#extract

MyModel.objects.order_by('birthday__month', 'birthday__day')

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Dan Tagg
Sent: Tuesday, November 21, 2017 12:58 PM
To: django-users@googlegroups.com
Subject: Re: How to get as result a list of all the users ordered by birthday 
(month day), ignoring year

Hi Roberta,

I haven't tested it but assuming you want the ordering to happen within the 
database you may be able to do it with a combination of 
TIMESTAMPDIFF
 and 
MOD.

Something like MOD( TIMESTAMPDIFF( 'SECOND', birthday, '1900-01-01'), 31556951) 
assuming you're using MySQL.

On average there are 365.2425 days per year, which equates to 31,556,951 
seconds.

Dan

On 21 November 2017 at 15:52, Roberta Takenaka Granero 
mailto:takenaka.robe...@gmail.com>> wrote:
Dear Roy
I had already seen that link. But I didn't like the solution. Anyway it works, 
so I am using it for while.

Thank you

2017-11-17 11:13 GMT-02:00 Roy Shillingburg 
mailto:roy...@gmail.com>>:
https://stackoverflow.com/questions/4236226/ordering-a-django-queryset-by-a-datetimes-month-day



On Friday, November 17, 2017 at 7:19:43 AM UTC-5, Roberta Takenaka Granero 
wrote:
In models:

birthday = models.DateField()

def birthday_month_day(self):
  # returns month and day
  return '12-31'


In views, I expect to see something pythonic like this:

User.objects.all().order_by('birthday_month_day')

I know it does not work because birthday_month_day is not a column in database.

The question is how to get as result a list of all the users ordered by 
birthday (month + day), ignoring year. (queryset order_by DateField month day)

Can you help me? Anyone has faced this question before?

Thanks



--
Roberta Takenaka
--
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/97d66095-d7a5-42c9-ad99-673fac39dac5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Roberta Takenaka
--
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/CAJ9dYMGUbq-QF%3Devx7u%3DtLPatWYUKCQQ0Qd-ks9Sjs3f_kP8SA%40mail.gmail.com.

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



--
Wildman and Herring Limited, Registered Office: 28 Brock Street, Bath, United 
Kingdom, BA1 2LN, Company no: 05766374
--
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/CAPZHCY4OyC9XnEMjSfbT6G9Zd6K1-TOa6ZPukw%3DowcLG3xUW7w%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 th

Recursive Queries

2017-11-29 Thread Matthew Pava
I have a problem in which I would like to solve with SQL recursive queries 
using the ORM (a bill of materials tree, actually).  In particular, I was 
looking at PostgreSQL's WITH RECURSIVE statement.
I discovered this paper in my research, which seems to indicate that Django had 
such a feature or one of its packages had such a feature.  Unfortunately, I 
cannot seem to locate the code that it seems to make a reference to.

https://www.researchgate.net/publication/221318255_Efficient_Implementation_of_Recursive_Queries_in_Major_Object_Relational_Mapping_Systems#pf6

Does Django have a recursive query feature?  If so, how do we access it/can we 
have documentation?  If not, shouldn't the feature be implemented?

-- 
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/83207698b2364e2c82e6a2bfdec85552%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Recursive Queries - CTEs

2017-11-29 Thread Matthew Pava
I’ve done more research.  The proper term of these Recursive Queries is Common 
Table Expressions (CTEs).  I learned that a developer had already worked on 
trying to get these in Django more towards the beginning of this year, but it 
doesn’t look like it was taken.

Django-mptt looks like it will do I what I need it to do, but it’s not what I 
really…want.  It adds all this extra overhead to traverse a tree, but modern 
databases can utilize the WITH RECURSIVE statement to get the same results.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Jason
Sent: Wednesday, November 29, 2017 1:44 PM
To: Django users
Subject: Re: Recursive Queries

If I understand you correctly, you're looking for something similar to a tree 
structure, but with a regular SQL db.

If so, there are two projects you can consider:

https://github.com/django-treebeard/django-treebeard
https://github.com/django-mptt/django-mptt
--
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/2eaf6b1e-984c-4e5b-9c0a-6f08211b3aef%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/56697eac4e4b4079ad74d4dfcef456d0%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: django 2.0 url to path

2017-12-06 Thread Matthew Pava
Is settings.DEBUG set to True?

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of ???
Sent: Tuesday, December 5, 2017 9:00 PM
To: Django users
Subject: django 2.0 url to path

i try to use path instead of url
but there are some problem

following is my code


oauth2_endpoint_views = ([
   path('authorize/', oauth2_views.AuthorizationView.as_view(), 
name='authorize'),
   path('token/', oauth2_views.TokenView.as_view(), name='token'),
   path('revoke-token/', oauth2_views.RevokeTokenView.as_view, 
name='revoke-token'),
], 'oauth2')



if settings.DEBUG:



   oauth2_endpoint_views += ([
   path('application/', oauth2_views.ApplicationList.as_view(), 
name='list'),
   path('application/register', 
oauth2_views.ApplicationRegistration.as_view(), name='register'),
   path('application//', oauth2_views.ApplicationDetail.as_view(), 
name='detail'),
   path('application//delete/', 
oauth2_views.ApplicationDetail.as_view(), name='delete'),
   path('application//update/', 
oauth2_views.ApplicationUpdate.as_view(), name='update'),
   path('authorized-tokens/', 
oauth2_views.AuthorizedTokensListView.as_view(), name='authorized-token-list'),
   path('authorized-tokens//delete/', 
oauth2_views.AuthorizedTokenDeleteView.as_view(), 
name='authorized-token-delete'),
   ], 'oauth2')





but i can't found page application, application/register/ 

how can i solve the problem...

plz help me


--
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/0dcd4fe4-baa5-4850-9e2b-5f87fc2b5d50%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/2bfa7f0d9dae4d699a096b17a5b793c2%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: django 2.0 url to path

2017-12-06 Thread Matthew Pava
Oh, and it looks like you need to add a “/” to the end of your 
'application/register' path.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Matthew Pava
Sent: Wednesday, December 6, 2017 8:26 AM
To: 'django-users@googlegroups.com'
Subject: RE: django 2.0 url to path

Is settings.DEBUG set to True?

From: django-users@googlegroups.com<mailto:django-users@googlegroups.com> 
[mailto:django-users@googlegroups.com] On Behalf Of ???
Sent: Tuesday, December 5, 2017 9:00 PM
To: Django users
Subject: django 2.0 url to path

i try to use path instead of url
but there are some problem

following is my code


oauth2_endpoint_views = ([
   path('authorize/', oauth2_views.AuthorizationView.as_view(), 
name='authorize'),
   path('token/', oauth2_views.TokenView.as_view(), name='token'),
   path('revoke-token/', oauth2_views.RevokeTokenView.as_view, 
name='revoke-token'),
], 'oauth2')



if settings.DEBUG:



   oauth2_endpoint_views += ([
   path('application/', oauth2_views.ApplicationList.as_view(), 
name='list'),
   path('application/register', 
oauth2_views.ApplicationRegistration.as_view(), name='register'),
   path('application//', oauth2_views.ApplicationDetail.as_view(), 
name='detail'),
   path('application//delete/', 
oauth2_views.ApplicationDetail.as_view(), name='delete'),
   path('application//update/', 
oauth2_views.ApplicationUpdate.as_view(), name='update'),
   path('authorized-tokens/', 
oauth2_views.AuthorizedTokensListView.as_view(), name='authorized-token-list'),
   path('authorized-tokens//delete/', 
oauth2_views.AuthorizedTokenDeleteView.as_view(), 
name='authorized-token-delete'),
   ], 'oauth2')





but i can't found page application, application/register/ 

how can i solve the problem...

plz help me


--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/0dcd4fe4-baa5-4850-9e2b-5f87fc2b5d50%40googlegroups.com<https://groups.google.com/d/msgid/django-users/0dcd4fe4-baa5-4850-9e2b-5f87fc2b5d50%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/2bfa7f0d9dae4d699a096b17a5b793c2%40ISS1.ISS.LOCAL<https://groups.google.com/d/msgid/django-users/2bfa7f0d9dae4d699a096b17a5b793c2%40ISS1.ISS.LOCAL?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

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


RE: [OT] Is Trump planning to break the Internet?

2017-12-11 Thread Matthew Pava
>> Please keep your political rhetoric and irresponsible scaremongering off 
>> this list.

>> All the net neutrality repeal will do is restore some of the permissionless 
>> innovation that allowed the internet to blossom in the first place.

Dear Larry,
Please read what you just wrote.  On the one hand, you asked Etienne not to 
share political rhetoric, and then you called Etienne's act one of 
irresponsible scaremongering.  And then you had to have the last word in this 
discussion by sharing your own political rhetoric about the topic.  That's not 
right, and I'm not going to sit by and let that happen.

The better way to handle it would have been a personal message to Etienne 
asking that user not to post political rhetoric (in a nicer way than you just 
did) and not make that message public.

So here's an article about Net Neutrality:
https://www.savetheinternet.com/net-neutrality-what-you-need-know-now

How would it affect Django and GitHub?  Well, ISPs could potentially charge 
extra money to be able to access the Django website, GitHub website, and other 
development package websites.  Put simply, fewer users could have access to 
these tools.

But, I agree, this is not really the mailing list to discuss these matters.


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Larry Martell
Sent: Sunday, December 10, 2017 5:35 PM
To: django-users@googlegroups.com
Subject: Re: [OT] Is Trump planning to break the Internet?

On Sun, Dec 10, 2017 at 5:24 PM, Etienne Robillard  wrote:
> Hey all,
>
> On December 14, the FCC will vote to repeal net neutrality and 
> possibly rig the Internet. This means that major corporations could 
> pay to have their content delivered faster while independent websites 
> traffic would be throttled. I think this is a outrageous move and 
> could seriously harm independent websites and communities from 
> reaching their key audience. We must not let this happen!
>
> Please share the word with your peers. It is imperative that we must 
> unite and act together to fight for our freedom of speech and prevent 
> the Internet from becoming obsolete. The Internet is a brilliant 
> technology allowing billions of people to share their knowledge 
> independently. We must defend at all costs its very own foundations 
> and protect it from censorship and tyranny!

Please keep your political rhetoric and irresponsible scaremongering off this 
list.

All the net neutrality repeal will do is restore some of the permissionless 
innovation that allowed the internet to blossom in the first place.

--
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/CACwCsY6xLxfMMLA1te%2Bn0WD8AurqO-fQzp3j%2B-irasaT7EVY-Q%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/b2a5e621368848e384a0a8191285e737%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


PRIMARY KEY in view PostgreSQL

2017-12-11 Thread Matthew Pava
Fellow users,
I have an unmanaged model that references a view in my PostgreSQL 9.5 backend.  
I am trying to apply an annotation through the ORM in that model's manager.  
Unfortunately, I am getting an error that some fields "must appear in the GROUP 
BY clause or be used in an aggregate function."

Upon further investigation, it appears that I need a PRIMARY KEY in the backend 
to avoid having to include columns in a GROUP BY clause, but PostgreSQL does 
not allow for such constraints to be added to a VIEW.  The "id" column is just 
a row_number().

I was wondering how anyone else handled this issue.
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/32e312a8f0284745855651d683e3c499%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: PRIMARY KEY in view PostgreSQL

2017-12-11 Thread Matthew Pava
Thank you so much, Simon, for that response!  I do wish I could use Django 2.0, 
but some of my third-party apps haven’t been updated yet.  I’m using Django 
1.11.

With the clues provided, I was able to test my query by adding all of the 
columns into the GROUP BY clause in my PostgreSQL SQL editor.  In the process, 
I learned that my query takes way too long to run (about 5 minutes).

As you requested, I added a message to the django-developers mailing list on 
that particular thread.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Simon Charette
Sent: Monday, December 11, 2017 1:35 PM
To: Django users
Subject: Re: PRIMARY KEY in view PostgreSQL

Hello Matthew,

This should be fixed in Django 2.0 by 
daf2bd3efe53cbfc1c9fd00222b8315708023792[0].

I'd appreciate if you could chime in the related django-developer thread[1] to 
mention
you were using an unmanaged model to query views as there was no consensus
regarding whether or not the patch should be rolled back.

I think you're a great example of a user who hit this issue from starting to 
use Django
< 2.0 that is not taken into account by one of the user argument to favor 
rolling back
the patch[2].

The more I think of it the more I feel like we should just close the ticket 
until the
ORM gains enough introspection power to determine whether or not we should be
using the optimization on unmanaged model.

Here's the Trac ticket for reference[2].

Cheers,
Simon

[0] 
https://github.com/django/django/commit/daf2bd3efe53cbfc1c9fd00222b8315708023792
[1] https://groups.google.com/forum/#!topic/django-developers/lx3ZSq-W9X4
[2| https://groups.google.com/d/msg/django-developers/lx3ZSq-W9X4/yh4I2CsoBwAJ
[3] https://code.djangoproject.com/ticket/28107


Le lundi 11 décembre 2017 10:43:34 UTC-5, Matthew Pava a écrit :
Fellow users,
I have an unmanaged model that references a view in my PostgreSQL 9.5 backend.  
I am trying to apply an annotation through the ORM in that model’s manager.  
Unfortunately, I am getting an error that some fields “must appear in the GROUP 
BY clause or be used in an aggregate function.”

Upon further investigation, it appears that I need a PRIMARY KEY in the backend 
to avoid having to include columns in a GROUP BY clause, but PostgreSQL does 
not allow for such constraints to be added to a VIEW.  The “id” column is just 
a row_number().

I was wondering how anyone else handled this issue.
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/f89fa330-0c6b-43eb-ae86-7926b67669ab%40googlegroups.com<https://groups.google.com/d/msgid/django-users/f89fa330-0c6b-43eb-ae86-7926b67669ab%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

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


RE: My Polls app question not displaying

2017-12-14 Thread Matthew Pava
You context dictionary key is “latest_question_list”, and this is passed into 
your template.  Your python variable is named latest_ques, which the template 
is not aware of.
So you need to change your html temple or your context key.

Also, watch your case.  “question” and “Question” are two different variables.






Polls


{% if latest_question_list %}

{% for question in latest_question_list %}
{{ question.question_text 
}}
{% endfor %}

{% else %}
No polls are available.
{% endif %}





From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of anyi.lloyd
Sent: Thursday, December 14, 2017 10:56 AM
To: Django users
Subject: My Polls app question not displaying

Am new to Django and python. for the past 5 hours i have been battling to make 
my polls question to display in the index.html, but is not.
These are the codes

Model

from django.db import models

class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

def __str__(self):
return self.question_text

class Choice(models.Model):
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
question = models.ForeignKey(Question, on_delete=models.CASCADE)

def __str__(self):
return self.choice_text



views

from django.shortcuts import render
from django.http import HttpResponse
from .models import Question

def index(request):
latest_ques = Question.objects.order_by('-pub_date')[:5]
context = {'latest_question_list': latest_ques}
return render(request, 'polls/index.html', context)

def detail(request, question_id):
return HttpResponse ("This a detail view of question: 
{}.".format(question_id))

def result(request, question_id):
return HttpResponse ("This a result view of question: 
{}.".format(question_id))

def vote(request, question_id):
return HttpResponse ("This a vote view of question: 
{}.".format(question_id))



Index.html





Polls


{% if latest_ques %}

{% for question in latest_ques %}
{{ Question.question_text 
}}
{% endfor %}

{% else %}
No polls are available.
{% endif %}






Please need help guys. 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/44d61c17-1cac-4126-99ff-b6e0c1ca61c4%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/02a08c6b3a154f8ab6883c7190a2d9a9%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: custom permission strings: Avoid magic strings ...

2017-12-15 Thread Matthew Pava
I use the perms object in my templates.
{% if perms.app_name.fooperm %}
{% endif %}
See https://docs.djangoproject.com/en/2.0/topics/auth/default/#permissions


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of guettli
Sent: Friday, December 15, 2017 8:09 AM
To: Django users
Subject: custom permission strings: Avoid magic strings ...

Hi,

We define the permission like in the docs: 
https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#custom-permissions

To avoid the magic string 'fooapp.fooperm' in the code which uses the 
permission very often, I choose this solution:

{{{
# file models.py
class FooModel(Model):

FOOPERM_PERMISSION_STRING='fooapp.fooperm'

class Meta:
permissions = (
('fooperm', 'Foo Permission'),
)
}}}


{{{
# file views.py
# This and other files use the permission string very often.

...
if request.user.has_perm(FooModel.FOOPERM_PERMISSION_STRING):
...
}}}


But still I am not happy with the above solution. I think it looks ugly.

How do you avoid the magic permission string in your code?

Regards,
  Thomas Güttler

--
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/21f0b282-66fb-46fb-9513-8f4db19b4cf1%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/af4a77b44fa843e1b16a1594ec281dd9%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: print option with django application

2017-12-19 Thread Matthew Pava
We use gsprint (for Windows printing) and Ghostscript.
http://pages.cs.wisc.edu/~ghost/gsview/gsprint.htm
https://www.ghostscript.com/

We have generic print view, and when users click on a button on the UI, our app 
generates a PDF and then sends that to a printer on the local network.  The 
printers are all set up under the user who is running the web server, in this 
case, Apache.  To print to printers at the user's desk, we turned on print 
sharing for those printers and set up the web server user to be able to print 
to those from the server hosting the webserver.  We have a model, 
ComputerProfile, that associates a shared printer with a client computer.  If 
the user is logged into that computer, the app choose the printer at that 
computer.  There is also a default printer as a fall back.

Yes, you can print directly to a printer from Django (or any web app) using 
this method.

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of johnf
Sent: Tuesday, December 19, 2017 8:38 AM
To: django-users@googlegroups.com
Subject: Re: print option with django application

I wonder what solutions there are for print from a django app? Is it possible 
to use reportlab for example.  Or is there some other solution that is normally 
used from django apps?

Johnf


On 12/19/2017 05:47 AM, Larry Martell wrote:
> On Tue, Dec 19, 2017 at 1:50 AM, Ketul Suthar  wrote:
>> I want to print data from database when user click on print button.
>>
>> how can I achieve it ?
>>
>> Is there any in-built module in djnago for printing data ?
> You cannot force the user to print. What I do in these situations is 
> generate a pfd (with wkhtmltopdf) and then the user can print that.
>

--
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/d7bf8abe-f500-f97d-d9bd-836d12620ff7%40jfcomputer.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/1e3b462fa0d046168994f38a7eea9b3b%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: How to store multiple object reference in one field?

2017-12-26 Thread Matthew Pava
Use a many-to-many field instead.
https://docs.djangoproject.com/en/2.0/topics/db/models/#many-to-many-relationships


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Hasanul Islam
Sent: Tuesday, December 26, 2017 9:52 AM
To: Django users
Subject: How to store multiple object reference in one field?

Suppose, I have a model
class Project(models.Model):
name = models.CharField(max_length=50)
Another model,
   class Manager(models.Model)
 name = models.CharField(max_length = 50)
 projects = ArrayField( models.Foreignkey(Project, 
on_delete=models.PROTECT) )

Here, projects field would be an array of Project object. But it is PostgreSQL 
specific. How can I implement this so that it will be useful for every database?
--
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/1f3a4691-fb23-4a42-9387-ea67562635c3%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/7ca4ccae24404cea8643dccc6c42fef3%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Possible bug Django 2.0 CreateView generic CBV

2017-12-28 Thread Matthew Pava
The problem is in your HTML template.
Your form tag really only has to be this (the action attribute should be a URL; 
otherwise, it assumes the current URL):



From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Steven Meyer
Sent: Thursday, December 28, 2017 7:44 PM
To: Django users
Subject: Possible bug Django 2.0 CreateView generic CBV

I hope I've got the right group this time. I originally posted it on Django 
core membership but Tim Graham emailed me to say it was the wrong group.

I am very new to Django - been at it for five weeks. Not sure whether this is a 
bug or my own stupidity.

Here is my model in an app called gcbv (for generic class-based view)

from django.db import models
from core.models import TimeStampModel
from django.urls import reverse
# Create your models here.

class Vehicle(TimeStampModel):
maker = models.CharField(max_length=100)
model_year = models.IntegerField()
vehicle_type = models.CharField(max_length=100)
slug = models.SlugField(max_length=100, unique=True)
vehicle_model = models.CharField(max_length=100)
website = models.URLField(max_length=100, blank=True)
email = models.EmailField(max_length=100, blank=True)
notes = models.TextField(blank=True, default='')


def __str__(self):
x = self.maker + ' ' + self.vehicle_model
return x


And here are the URLs

from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url
from . import views
from django.urls import reverse
#from django.views.generic.base import TemplateView

app_name = 'gcbv'

urlpatterns = [
path('sub1/', views.SubView.as_view(), name='sub1'),
path('vehicle_list/', views.VehicleListView.as_view(),
name = 'vehicle_list'),
path('vehicle//',
views.VehicleDetailView.as_view(),
name='vehicle_detail'),
path('vehicle/create', views.VehicleCreateView.as_view(),
name='vehicle_create'),
path('', views.IndexTemplateView.as_view(), name='index'),
]

And here is the relevant view

class VehicleCreateView(CreateView):
model = Vehicle
fields = ['maker', 'model_year', 'vehicle_type', 'slug',
'vehicle_model', 'website', 'email', 'notes']
labels = {'maker':'Maker', 'model_year':'Year',
'vehicle_type':'Type', 'vehicle_model':'Model',
'website':'Website', 'email':'Email', 'notes':'Notes'}


Here is the template:

{% extends "core/base.html" %}
{% block body_block %}
Vehicle Create for GCBV



  {% csrf_token %}
  {{ form.as_p }}
  Submit


End Vehicle Create for GCBV
{% endblock %}

I've attached screenshots of:

--The rendered form template

--What happens after I click submit

It looks as if the data is not being saved to the database.

If I add the same data from admin everything works fine. I've attached another 
screenshot showing that VehicleDetailView has found the relevant template and 
rendered the information.

Any help would be greatly appreciated.

NB: This all worked fine when I was using function views and regex instead of 
path.



--
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/5aa037bb-25d5-442d-b1a6-b1bbc558dead%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/f6d52c40872a4c4c968bcaa6d34ce2a0%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Django 2.0.1 admin

2018-01-05 Thread Matthew Pava
Hi everyone,
I am finally able to move to Django 2.0, but I just noticed an error I keep 
getting when attempting to open the admin:

TemplateSyntaxError at /admin/
Invalid block tag on line 58: 'get_admin_log', expected 'endblock'. Did you 
forget to register or load this tag?

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/4dbdb1ab1c37482eb2150fd8f6cd3426%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Django 2.0.1 admin

2018-01-05 Thread Matthew Pava
No.  I even uninstalled Django and reinstalled Django, but the issue persists.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of m1chael
Sent: Friday, January 5, 2018 4:25 PM
To: django-users@googlegroups.com
Subject: Re: Django 2.0.1 admin

did you ever override your admin templates?

On Fri, Jan 5, 2018 at 5:20 PM, Matthew Pava 
mailto:matthew.p...@iss.com>> wrote:
Hi everyone,
I am finally able to move to Django 2.0, but I just noticed an error I keep 
getting when attempting to open the admin:

TemplateSyntaxError at /admin/
Invalid block tag on line 58: 'get_admin_log', expected 'endblock'. Did you 
forget to register or load this tag?

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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/4dbdb1ab1c37482eb2150fd8f6cd3426%40ISS1.ISS.LOCAL<https://groups.google.com/d/msgid/django-users/4dbdb1ab1c37482eb2150fd8f6cd3426%40ISS1.ISS.LOCAL?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/CAAuoY6PCXSrmZpYgXwHfUMs0rcz_g3JFmsexHnL_JOfaWXbzTQ%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CAAuoY6PCXSrmZpYgXwHfUMs0rcz_g3JFmsexHnL_JOfaWXbzTQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

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


RE: Django 2.0.1 admin

2018-01-08 Thread Matthew Pava
I found the problem.  I had a third-party app, django-audit-log, that I 
incorporated into the project since it was not working with Django 2.0.  I 
needed to list ‘audit_log’ in the APPS list before django.contrib.admin in my 
Django settings module.

Problem solved!  Thank you!

From: Matthew Pava
Sent: Friday, January 5, 2018 4:27 PM
To: 'django-users@googlegroups.com'
Subject: RE: Django 2.0.1 admin

No.  I even uninstalled Django and reinstalled Django, but the issue persists.


From: django-users@googlegroups.com<mailto:django-users@googlegroups.com> 
[mailto:django-users@googlegroups.com] On Behalf Of m1chael
Sent: Friday, January 5, 2018 4:25 PM
To: django-users@googlegroups.com<mailto:django-users@googlegroups.com>
Subject: Re: Django 2.0.1 admin

did you ever override your admin templates?

On Fri, Jan 5, 2018 at 5:20 PM, Matthew Pava 
mailto:matthew.p...@iss.com>> wrote:
Hi everyone,
I am finally able to move to Django 2.0, but I just noticed an error I keep 
getting when attempting to open the admin:

TemplateSyntaxError at /admin/
Invalid block tag on line 58: 'get_admin_log', expected 'endblock'. Did you 
forget to register or load this tag?

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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/4dbdb1ab1c37482eb2150fd8f6cd3426%40ISS1.ISS.LOCAL<https://groups.google.com/d/msgid/django-users/4dbdb1ab1c37482eb2150fd8f6cd3426%40ISS1.ISS.LOCAL?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/CAAuoY6PCXSrmZpYgXwHfUMs0rcz_g3JFmsexHnL_JOfaWXbzTQ%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CAAuoY6PCXSrmZpYgXwHfUMs0rcz_g3JFmsexHnL_JOfaWXbzTQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

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


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread matthew . pava
Check this out for how to redirect:
https://docs.djangoproject.com/en/2.0/topics/http/shortcuts/#redirect

Check this out for how Django determines the name of primary key fields:
https://docs.djangoproject.com/en/2.0/topics/db/models/#automatic-primary-key-fields

The best advice has already been provided: Get a random post id from your 
model and then redirect to the DetailView of that post.  You can figure it 
out.

On Monday, January 8, 2018 at 10:41:28 AM UTC-6, Ronnie Raney wrote:
>
> Please give me code. Sorry, I can't decipher plain language in forums very 
> well, when talking about code.
>
> My urlpattern:   
>
>  path('post//', views.PostDetailView.as_view(), 
> name='post_detail'),
>  path('post/*random*/*???*', views.random_post, name='random_post'),  *### 
> What do I put here?*
>
> My view:
>
> def random_post(request):
> post_ids = Post.objects.all().values_list('*post_id*', flat=True) * 
>  ### Is this correct? My field name is post_id - the primary key.*
> random_obj = Post.objects.get(*pk*=random.choice(post_ids))   *### 
> What do I put here? pk, id, post_id?*
> context = {'random_obj':random_obj,}
> return render(request, 'blog/random_post.html', context)
>
>>
>>

-- 
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/4834d44e-cb98-4d0d-b656-ff2c05a486a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Admin case-insensitive sorting question

2018-01-10 Thread Matthew Pava
If I'm understanding you correctly, you could use a callable in the 
list_display definition.
https://docs.djangoproject.com/en/2.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display

def lower_case_name(obj):
return ("%s" % str(obj).lower()
lower_case_name.short_description = 'Substance'

class SubstanceAdmin(admin.ModelAdmin):
list_display = (lower_case_name,)

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Mike Dewhirst
Sent: Wednesday, January 10, 2018 1:03 AM
To: Django users
Subject: Admin case-insensitive sorting question

I have tried every which way to produce a case-insenstive list of substances in 
the Admin including this:

def get_queryset(self, request):
     return super(SubstanceAdmin,
self).get_queryset(request).order_by(Lower('name').asc())

Which DOES work (as proven via print statement) but doesn't display that way in 
the Admin which uses the natural ascii order. It is the list_display feature 
which re-orders the substances.

I can get them sorting pseudo-insensitively by using a method to uppercase the 
first char of the name and passing that method to list_display.

However, that prevents the column order reversal feature which is a function of 
the list_display feature.

I thought a case insensitive model manager might work until I saw in the docs 
that subsequent order_by filtering will spoil it and I would still have to 
pseudo_name them anyway.

So the question is ... should I bite the bullet and add a sort field to the 
model and fill it with the substance name converted to lower-case?

Thanks

Mike

--
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/b1fc1d23-b0ab-d35e-9049-9a4f6091a4f7%40dewhirst.com.au.
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/205b80f44a9f47569f5715825dc2c106%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Django ORM temporal tables with PostgreSQL

2018-01-10 Thread Matthew Pava
Temporal tables are not part of Django, but you could try to manually make 
them.  Saying that, it appears that are at least a couple of Django packages 
that try to make it easier to use them in the ORM.
This one looks decent, but its build is not passing:  
https://github.com/arkhipov/temporal_tables
This one looks like it just started:  https://github.com/zejn/django_temporal



From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of D_lane
Sent: Wednesday, January 10, 2018 10:09 AM
To: Django users
Subject: Django ORM temporal tables with PostgreSQL

Hey all,

I am lost with this topic.. I am fairly comfortable using Python to interact 
with PostgreSQL and generate temporal tables. However, when it comes to using 
the Django ORM I am finding it next to impossible to find links or any examples 
online ..

Any suggestions where to find some material on this topic would be great.

Kind Regards,
Donal
--
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/a337d120-a49d-4b54-a567-4f102c8c90de%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/3379747a8ff343819b457299f69c6eef%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: HTTP Error 403: Forbidden

2018-01-11 Thread Matthew Pava
Typically, that indicates a permissions problem.  Are you signed in to your 
app?  Does the account you are signed into have permissions to access that URL? 
 Check your decorators.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of mohammad
Sent: Thursday, January 11, 2018 8:11 AM
To: Django users
Subject: HTTP Error 403: Forbidden

hi,  i try to submit a form but it gives me this err
if any one can help me

Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/images/create/

Django Version: 1.8.6
Python Version: 3.6.1
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'account',
 'django.contrib.admin',
 'social.apps.django_app.default',
 'images',
 'medic',
 'sorl.thumbnail')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:
File 
"C:\Users\mohammad\Documents\Scripts\dj_env\Packt.Django.By.Example.2015\env\bookmarks\lib\site-packages\django\core\handlers\base.py"
 in get_response
  132. response = wrapped_callback(request, *callback_args, 
**callback_kwargs)
File 
"C:\Users\mohammad\Documents\Scripts\dj_env\Packt.Django.By.Example.2015\env\bookmarks\lib\site-packages\django\contrib\auth\decorators.py"
 in _wrapped_view
  22. return view_func(request, *args, **kwargs)
File 
"C:\Users\mohammad\Documents\Scripts\dj_env\Packt.Django.By.Example.2015\env\bookmarks\bookmarks\images\views.py"
 in image_create
  47. new_item = form.save(commit=False)
File 
"C:\Users\mohammad\Documents\Scripts\dj_env\Packt.Django.By.Example.2015\env\bookmarks\bookmarks\images\forms.py"
 in save
  28. response = request.urlopen(image_url)
File "c:\python\Lib\urllib\request.py" in urlopen
  223. return opener.open(url, data, timeout)
File "c:\python\Lib\urllib\request.py" in open
  532. response = meth(req, response)
File "c:\python\Lib\urllib\request.py" in http_response
  642. 'http', request, response, code, msg, hdrs)
File "c:\python\Lib\urllib\request.py" in error
  570. return self._call_chain(*args)
File "c:\python\Lib\urllib\request.py" in _call_chain
  504. result = func(*args)
File "c:\python\Lib\urllib\request.py" in http_error_default
  650. raise HTTPError(req.full_url, code, msg, hdrs, fp)

Exception Type: HTTPError at /images/create/
Exception Value: HTTP Error 403: Forbidden
--
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/4a1387e6-5a74-47cf-9134-149fbbd14ecf%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/268bcdadc5bd471a85059f61a619d445%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Getting Outlook Calendar In Django web page

2018-01-17 Thread Matthew Pava
You might want to look into this 3rd-party package that will give you access to 
the Exchange API.
https://github.com/ecederstrand/exchangelib


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Harrison Latimer
Sent: Wednesday, January 17, 2018 3:59 PM
To: Django users
Subject: Getting Outlook Calendar In Django web page

I have tried taking an available bootstrap calendar and feeding calendar items 
via JSON file but I'd rather find a way to export a static outlook calendar to 
my django web page. Is this possible?

-Harrison
--
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/4d512f8e-8840-466f-b77b-b56a80e6865e%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/d951629d485f4eebb44f6041cc0dbb43%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Strange the global variable behavior

2018-01-23 Thread Matthew Pava
I think the primary suggestion would be to not use global variables.  Is there 
any way you could re-implement the function without using those global 
variables?  Maybe creating a variable in the settings file for you to use?
If you can’t, is there possibly a problem with the get_wb_pdf_as_zip function?

As an aside, I also suggest using render(request, template_name, context_dict) 
instead of render_to_response().

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of ?? ???
Sent: Tuesday, January 23, 2018 5:48 AM
To: Django users
Subject: Strange the global variable behavior

Hi there.
Could someone explain what happens. I had a little project on Python 2.7 and 
decided to move it on 3.6. Everything has gone by perfectly. The project works 
well as before but there is one exception noticed by me: the global statement 
works not always. The code below doesn't update the global variable 
zip_file_name and I can't grasp why. Any suggestions.


zip_file_name = os.path.join(MEDIA_ROOT, 'wb`s.zip')
file_list = []


@permission_required("wb_search.change_wbsearch", login_url='access_denied')
@csrf_exempt
def input_data_form(request):
global zip_file_name, file_list
if request.method == 'POST':
form = WbSearchForm(request.POST)
if form.is_valid():
text = request.POST['wbs_nums']
picked = form.cleaned_data.get('category')
try:
wb_nums = process_input(text, LENGTH_OF_STR_TO_PROCESS)
zip_file_name, file_list = get_wb_pdf_as_zip(wb_nums, picked)
m = SearchHistory(user=str(request.user), 
curr_date=datetime.now(), list_desired_docs=', '.join([str(rec[0]) for rec in 
file_list]))
m.save()
return HttpResponseRedirect('/wb_search/search_finished/')
except NoDataToSearch:
return 
HttpResponseRedirect('/wb_search/wb_search_incorrect_data/')
else:
return HttpResponseRedirect('/wb_search/wb_search_incorrect_data/')
else:
form = WbSearchForm()
# context = context.update(csrf(request))
return render_to_response('wb_search_input_data_form.html',
  {'form': form, 'title': 'Номера для поиска',
   'header': 'Поиск PDF файлов вэйбилов',
   'text': 'Вставте в это поле номера вэйбилов PDF 
файлы которых необходимо найти.',
   'textarea_title': 'Вставте в это поле номера 
вэйбилов PDF файлы которых необходимо '
 'найти.',
   'submit_title': 'Начать поиск',
   'element_id': 'find_button', 'element_method': 
'click',
   'spinner_message': 'Ожидайте окончания 
поиска...', },
  RequestContext(request))
--
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/e833541c-0b75-486c-a06e-5aa8ccb5d446%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/238cb955a51b4535990ba1259270e7c3%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: javascript transpilers

2018-01-31 Thread Matthew Pava
I just want to point out something called WebAssembly.  It's supported across 
all modern browsers.  Presumably, you can write a program in Python, convert it 
to WebAssembly, and it will run in your browser.  I haven't worked with it 
myself, but I am keeping my eye on it because I would like to think it will 
become more widely adopted in the not-so-distant future.
http://webassembly.org/


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Mike Dewhirst
Sent: Wednesday, January 31, 2018 4:29 PM
To: django-users@googlegroups.com
Subject: Re: javascript transpilers

On 30/01/2018 6:33 PM, Andréas Kühne wrote:
> 2018-01-30 5:18 GMT+01:00 Mike Dewhirst  >:
>
> On 29/01/2018 9:03 PM, Nick Sarbicki wrote:
>
> Going SPA when you don't know JS is very much a baptism of fire.
>
> Angular is personally my favourite too and essentially forces
> the SPA model. But it has a much bigger learning curve
> compared to Vue and React (the other two common names thrown
> about nowadays). The others are also easier to not force into
> a SPA model.
>
> Figure what's the minimum requirement first ;-).
>
>
> Single page is pretty close to the way the application currently
> works so that is promising. It is a lightweight training
> framework. Simple architecture of courses, instruction(s) and
> questions with answers aggregating a total score for the student.
>
> I won't publicise the URL because the server isn't heavy-duty. But
> if there is any individual interest I'm happy to give it off-list.
> Today I released the beta to the first client who (generously) is
> using it for his troops to do online training on how to use some
> Windows software.
>
> So back to the minimum requirement ...
>
> The single (question) page has previous-question and next-question
> links which morph into previous-instruction and next-instruction
> links when at the first and last question respectively. So that is
> the SPA similarity.
>
> When you click the [Save] button after answering a question there
> is no indication the answer has been saved without adding a line
> of text (via the view) after answer.save()
>
> Refreshing the page resends the [Save] and reprints the line of
> text saying the [Save] was successful. Too clunky.
>
>
> If you are using django in the "normal" way - you should just be able 
> to add the message to the messages contrib package. Then the message 
> should show when saving? Because when you click on the save button you 
> should post your form and that method should (when successful) add the 
> message?

Hadn't thought of that! Must investigate the messages package.


>
> It was that behaviour which made me start this thread.
>
> I checked out typescript and it looks great but it is javascript.
> It seems to let you code in ECMAScript 6 which is looking more
> like Python and as Nick mentioned, has a compilation step (which I
> suppose is like a minification step anyway) to get it into the
> version currently supported by all browsers.
>
>
> Typescript is more of a object oriented language than javascript is - 
> at least compared to ECMAScript 5. It also has some support for typing
> - and great unittest support - which is criticle when writing 
> javascript

Agreed

>
> That prompted me to look more closely at a few of the transpilers
> in the link I posted in the thread-starter. One stood out for me
> ... http://www.transcrypt.org/
>
> It seems the compilation to javascript takes place in the CI
> process and it can be debugged in Python or Javascript. You can
> use both javascript and/or python libraries. Written by a Dutchman
> which is possibly interesting ;)
>
>
> What you have to remember is that you still need to transpile it when 
> running in development mode. So it really doesn't matter where you do 
> your transpilation. You need to setup the transpilation even in 
> development - a webb browser can't run python natively.

True. However, Transcript produces Javascript. Interestingly you debug in 
python or Javascript.

I'll have to allocate some time to investigate but in any case I think DRF 
comes first.

>
> The Angular thing is interesting.
> 
> https://medium.com/@chriscordle/why-angular-2-4-is-too-little-too-late-ea86d7fa0bae
> 
>  e-ea86d7fa0bae>
>
> 
> https://www.infoworld.com/article/3213244/javascript/whats-new-in-angular-5-easier-progressive-web-apps.html
> 
>  ular-5-easier-progressive-web-apps.html>
>
> >From those articles, it seems React is lighter-weight than
> Angular and for me that probably means easier to learn. It is
> still da

RE: Migrating into Django 1.9; question about autoescape

2018-02-13 Thread Matthew Pava
At first, I would do your step 1.  I would check for any other errors in Django 
1.8, and then proceed with updating to 1.9 -> 1.10 -> 1.11 -> 2.0.  You are 
probably going to find other issues that need to be resolved in those upgrades. 
 Ultimately, you will probably have to do step 3.  I wouldn’t do step 2 since 
you’ll be updating all of your templates.  If you are going to update all your 
templates, you might as well just do step 3.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Bill Torcaso
Sent: Tuesday, February 13, 2018 8:54 AM
To: Django users
Subject: Migrating into Django 1.9; question about autoescape


Hello all,

I have the task of migrating a very old website from Django 1.7 to either 
Django 1.11 or 2.0, depending on the effort.

My plan is to go from 1.7 --> 1.8 --> 1.9 -->1.10 --> 1.11, adapting the 
codebase as I go.  It's been easy enough until I arrive at 1.9, and the change 
in template-rendering in which "autoescape" defaults to "on".

Now a lot of my payload is arriving at the browser with my HTML tags escaped.  
For example,

   gets rendered as

RE: AttributeError: 'module' object has no attribute 'lru_cache' with python 3.6.4 and Django 2.0.2

2018-02-14 Thread Matthew Pava
I’m not familiar with Docker, but I did have to add the path to Python 3.6 DLLs 
in my WSGI configuration in my Apache configuration file.
WSGIPythonPath ${project_path};${virtualenv};C:/Python36/DLLs;

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of PASCUAL Eric
Sent: Wednesday, February 14, 2018 8:52 AM
To: Django users
Subject: Re: AttributeError: 'module' object has no attribute 'lru_cache' with 
python 3.6.4 and Django 2.0.2


Hi,



Normally you shouldn't have to add site-packages in the PYTHONPATH since it is 
supposed to be already. If not, packages installed via "sudo pip install" would 
not be found.



I've packaged a lot of applications in Docker containers, and never had to 
modify PYTHONPATH.



Your problem is maybe be lurking elsewhere than PYTHONPATH, and this change has 
just created a new one which is hiding the original one, but not solving it at 
all.



Best


Eric

From: django-users@googlegroups.com 
mailto:django-users@googlegroups.com>> on behalf 
of Greng Fortezza mailto:greng@gmail.com>>
Sent: Wednesday, February 14, 2018 3:02:28 PM
To: Django users
Subject: AttributeError: 'module' object has no attribute 'lru_cache' with 
python 3.6.4 and Django 2.0.2

Hi,

I'm trying to set up the following configuration in Docker
python: 3.6.4
Django: 2.0.2
Apache/2.4.10 (Debian)

First, I was getting the error

ImportError: No module named django.core.wsgi

Then I added Django to PYTHONPATH

export PYTHONPATH="/usr/local/lib/python3.6/site-packages"

the previous problem has gone away but now there is another one

AttributeError: 'module' object has no attribute 'lru_cache'

Apache configs contains the following line

WSGIScriptAlias / /www/settings/wsgi.py

where /www/settings/wsgi.py is  actual path to wsgi.py file.

What could be wrong?

Thanks,
Greng
--
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/02803efb-92a9-4958-9a52-f77bee7de89b%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/AM5P193MB008328E4760DBF0DA724D2238CF50%40AM5P193MB0083.EURP193.PROD.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/f0cabae1fd6544528668a9494f6dfe03%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Basic note/trello app - how to link model object IDs

2018-02-14 Thread Matthew Pava
You’ll want to use card.get_absolute_url.
See https://docs.djangoproject.com/en/2.0/ref/models/instances/#get-absolute-url
In your get_absolute_url, you should probably use the reverse method to use the 
name of a URL rather than hard-coding it in the method.  That’s the second 
example in that section.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Lylio
Sent: Wednesday, February 14, 2018 9:15 AM
To: Django users
Subject: Re: Basic note/trello app - how to link model object IDs

Thanks for the reply Gonzalo, I really appreciate the feedback.

So, conceptually I understand how the remaining pieces of this app fit together 
- but could I ask for just a little more of your help as I'm struggling with 
coding the details of what's needed.

Let's start basic - I've got some 'cards' in my database and on one of the web 
pages the title of the card is presented in a list (with some CSS styling to 
present the list item as a rectangle):


   {% for card in cards.all %}
   {{ card.title }}  
   {% endfor %}


I'd like to click on one of the items in the list and open up a new page 
showing all the database details for that particular list item (title, 
description, time of creation, etc). Roughly, would I change the list items 
into links:


   {% for card in cards.all %}
1. To click on a card so it opens up and displays the details, am I right
> to say I should create a card.html file in the templates folder for this?

It isn't necessary, but it is a good idea
What you need is to create a view that renders such template.
I suggest you write your own view function that does that, but what
you'd usually do is just use a generic view and either pass it the
template you want to use, or name the template in a way the generic view
will find it on its own.
See:
https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-display/

> 2. I'm confused about how Django keeps track of the cards in my app - I
> presume each card object has an ID in the database and I'd need this
ID in
> order to retrieve the card's details when it's clicked - but I'm
unsure of
> how to link the two. In the two pictures above, say someone clicked on
the
> 'class progression' card on the left... I'd like a new page to open up
that
> display the details for that card and allows the user to edit the info or
> completely delete the card.

Yes, in general, every Django model instance has an id (unless you
specifically tell it not to), and you can use it to create urls for the
detail view I mentioned earlier. This is a good start, but you'll later
want to add a SlugField to your Card model, and use that instead of the
id so urls look nicer.

> I'm maybe asking a bit much here - but I'm unsure of how complex these
> requirements are. It feels like it should be *fairly *straightforward.
Any
> thoughts or advice would be greatly appreciated.

I can assure you using Django for a project like yours is *very*
straightforward.
When in doubt, revisit the Django tutorial. This part is a good one for
where you're at: https://docs.djangoproject.com/en/2.0/intro/tutorial03/


--
Gonzalo Delgado
--
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/eee70b8a-daff-453f-bb46-b4c2769d33e9%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/29197cad508a48fe881f19125a52c08f%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: django mathfiters

2018-02-21 Thread Matthew Pava
Check the value of b.value.  Make sure it isn’t None.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of sum abiut
Sent: Wednesday, February 21, 2018 4:06 PM
To: django-users@googlegroups.com
Subject: django mathfiters


Hi,
How to you a zero in mathfilter
for example, if the value of c is zero the total is not display. instead of 
displaying 42 it display nothing.

{%for b in pay%}

{% with a=42 c=b.value%}

 {{ a|add:c }}

{% endwith %}

--
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/CAPCf-y5F9bP8AVU2qXhXjMPhK4kwHBfWza2WL7j424VUkAgCRg%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/a975b53b163440e990433832734b598f%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: django mathfiters

2018-02-21 Thread Matthew Pava
And how are you checking if it’s None?  I would do it like this:
{% if c %}
{{ a|add:c }}
{% else %}
  {{ a }}
{% endif %}

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of sum abiut
Sent: Wednesday, February 21, 2018 4:43 PM
To: django-users@googlegroups.com
Subject: Re: django mathfiters

Thanks for your response. Yes the value was actually None. how to i display 42  
instead of not displaying anything at all. I have try using the if statement to 
check for the value of c if its None i just display the value of a, and if is 
not None i add the values. But still its displaying nothing.

Thanks

On Thu, Feb 22, 2018 at 9:15 AM, Matthew Pava 
mailto:matthew.p...@iss.com>> wrote:
Check the value of b.value.  Make sure it isn’t None.

From: django-users@googlegroups.com<mailto:django-users@googlegroups.com> 
[mailto:django-users@googlegroups.com<mailto:django-users@googlegroups.com>] On 
Behalf Of sum abiut
Sent: Wednesday, February 21, 2018 4:06 PM
To: django-users@googlegroups.com<mailto:django-users@googlegroups.com>
Subject: django mathfiters


Hi,
How to you a zero in mathfilter
for example, if the value of c is zero the total is not display. instead of 
displaying 42 it display nothing.

{%for b in pay%}

{% with a=42 c=b.value%}

 {{ a|add:c }}

{% endwith %}

--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/CAPCf-y5F9bP8AVU2qXhXjMPhK4kwHBfWza2WL7j424VUkAgCRg%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CAPCf-y5F9bP8AVU2qXhXjMPhK4kwHBfWza2WL7j424VUkAgCRg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/a975b53b163440e990433832734b598f%40ISS1.ISS.LOCAL<https://groups.google.com/d/msgid/django-users/a975b53b163440e990433832734b598f%40ISS1.ISS.LOCAL?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.



--
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/CAPCf-y4%3D_cMyrBTU177Pqkd74GUzqurAyYsmHWL-CtakR6r%3DMA%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CAPCf-y4%3D_cMyrBTU177Pqkd74GUzqurAyYsmHWL-CtakR6r%3DMA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

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


RE: How to get Foreign Key Objects programmatically?

2018-02-28 Thread Matthew Pava
You may want to look at the model _meta API.
https://docs.djangoproject.com/en/2.0/ref/models/meta/

You are looking for a list of all the ForeignKeys, but you also probably want 
other relations such as OneToOne and ManyToMany.
You probably want something like the get_all_related_objects method:
https://docs.djangoproject.com/en/2.0/ref/models/meta/#migrating-from-the-old-api

The fields have an attribute called is_relation, one_to_one, and many_to_one.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Rob Schneider
Sent: Tuesday, February 27, 2018 10:46 PM
To: django-users@googlegroups.com
Subject: Re: How to get Foreign Key Objects programmatically?

Still a mystery to me.

--rms


On 28 Feb 2018, at 03:22, Malik Rumi 
mailto:malik.a.r...@gmail.com>> wrote:
Did you ever find an answer? If so, do you mind sharing it? Thanks.

On Sunday, October 29, 2017 at 9:33:10 AM UTC-7, rmschne wrote:
I'm using Django as front end to a MySQL database. User interface is a terminal 
program, not a web site.

I've written a very simple generic function to edit the fields of one record of 
a Django "object".  It works fine for editing editable fields. User specifies 
which field, then is shown the current value, raw_input() for the new value, 
then save() the record.

For fields that connect to Foreign Keys, what I want to do is present to user a 
simple list of Foreign Key records, from which the user will pick the relevant 
ID.  I know, given a list and the ID, how to then edit the record by doing a 
Django get(id=ID) on the Foreign Key table.  What I'm having trouble doing is 
figuring how

1. Identify into a variable the name of the Foreign Key table/object
2. Then with that variable do a call to the relevant Foreign Key table, e.g. 
ForeignKeyTable.objects.all()

See code below for <===WHAT I DO NOT KNOW HOW TO DO IN CODE Below.  I think I 
need some Django function that gives me the foreign key table in some useable 
generic form.

Hope all this makes sense.

--rms

def EditDjangoObjectData(djangoobject,show=False,editonerecord=False):
"""
EditDjangoObjectData()
djangoojbect=a django object, e.g. a record in a table
"""
print "\nToDo Note: This routine not yet working on fields with foreign 
keys!"
changelist=[]
ok=True
while ok:
change=None
fields = [(f.name, f.editable) for f in 
djangoobject._meta.get_fields()]
if show:
print "\nfields:\n",fields
print "django object:\n",djangoobject
s="\nEditable Fields ('enter' to return): \n"
fieldlist=[]
for i in fields:
if i[1]:   # only for 'editable' fields
if i[0].lower() <> "id":
s=s+i[0]+", "
fieldlist.append(i[0])
s=s+"DELETE or '?'"
fieldok=False
while not fieldok:
fieldtochange=raw_input("Enter field name to change:\n"+s+": ")
if not fieldtochange:
return None
elif fieldtochange.upper()=="DELETE":
ans=raw_input("...Confirm DELETE by typing 'DELETE': ")
try:
if ans=="DELETE":
rtn=djangoobject.delete()
print "Deleted. ",rtn
return rtn
except:
print "***DELETE Failed.",sys.exc_info()[0]
ans=raw_input("Press 'Enter' to continue ... ")
elif fieldtochange=="?":
PrintObjectDetails(djangoobject)
elif fieldtochange in fieldlist:
fieldok=True
else:
print "\nError. ",fieldtochange,"is not in list. Try again."
print "Current Value of Field to 
Change:",fieldtochange,"is:",getattr(djangoobject, fieldtochange)
**
** In here add some code to show a list of the foreign key records for user to 
select, e.g. ID, Description,
**for r in ForeignKey.objects.all():   <== WHAT I DO NOT KNOW HOW TO DO IN CODE.
**print i.id, i.description
**ID=raw_input("Enter ID:)
**foreignkeyobject=ForeignKey.objects.get(id=ID)<== WHAT I DO NOT KNOW HOW 
TO DO IN CODE.
** ... then put that object into the relevant field
newvalue=raw_input("Enter New Value: ")
change="changed ["+fieldtochange+"]"
print "\nTo Save   :",djangoobject
print "The Change:",change,"to",newvalue
if not newvalue:
return None
elif newvalue.lower()=="none":
newvalue=None
elif newvalue.lower()=="true":
newvalue==True
elif newvalue.lower()=="false":
newvalue=False
setattr(djangoobject, fieldtochange, newvalue)
try:
djangoobject.save()
print ": Success. Saved:",change,"to",newvalue
print ": New Object:",djangoobject
changelist.append(change)
print "Change

RE: Making an object unsaveable ...

2018-03-05 Thread Matthew Pava
You can always override the save method on the model.  If you need to make all 
your models override the save method, use inheritance.

class DoNotSaveModel(models.Model):
 def save(*args, **kwargs):
pass

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of bill.torcaso
Sent: Monday, March 5, 2018 8:48 AM
To: Django users
Subject: Re: Making an object unsaveable ...



On Sunday, March 4, 2018 at 4:43:06 AM UTC-5, Bernd Wechner wrote:

An interesting question I've not been able to solve reading docs or Googling. 
As every posting here only after some serious research efforts including class 
inspections ;-). But am stumped and wonder if anyone else has any ideas.

Here is the use case:

  1.  Load an object from database
  2.  Flag it as unsaveable, not to be written back to database under any 
circumstances
  3.  Make changes to the object (its fields)
  4.  Present a detail view of the object.

Basically, would like the freedom to change an object knowing the database is 
secure.

As ever, am more interested in how to do this, than questioning why to do it. 
It may not be possible in which case fear not, I'm on top of the why's and can 
look at alternative strategies. But this use case provides an easy way of 
injecting some filters in one place of a code body I have without changing any 
of the views or other code. Simply one small hook I place into extant code, 
which will play around with the object (making translations for example). But 
in order to do so would want to know this cannot be written back to the 
database, that from here on in, it's for display purposes only.

Have a suspicion after some research that this can't be done. In which case 
there's a second and almost as useful use case:

  1.  Load an object from database
  2.  Make a copy, that is unsaveable, not to be written back to database under 
any circumstances
  3.  Make changes to the copy (its fields)
  4.  Present a detail view of the copy.

This has some slightly better chance of being possible. If not as well, yes 
indeed, I have to dive into the view itself and put hooks into each field as it 
renders I guess. Which is life. But would seem useful to do it with one of 
these use cases (again no need to discuss the merits of one approach over the 
other at all, am more interested in possibility - projects have huge amounts of 
context not readily shareable that influence the relative merits of one 
approach over another of course.

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/c25f6674-9d58-408c-8e94-c7f49ca2cd59%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/28aa8fe8564b4d56acf5e69b23e63502%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: unable to render initial data in ModelForm called through CreateView

2018-03-06 Thread Matthew Pava
Let's see InvoiceForm.
Also, it doesn't make much of a different, but I wouldn't call copy on the 
super.get_initial() method.

 
-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Gabriel Wicki
Sent: Sunday, March 4, 2018 2:48 PM
To: django-users@googlegroups.com
Subject: unable to render initial data in ModelForm called through CreateView

hello list

i ran into some weird stuff and neither i nor 2 gentle folks down at the 
irc-chat could find any obvious problems. task should have been easy:
calculate some special initial data and present it as initials in a form. the 
form is showed correctly, and the right values are printed in console.. and, of 
course, there is no error raised..

thank you for any hints! i've been stuck here


gabriel




# models.py
class AmountModel(models.Model):
    class Meta:
    abstract = True
    currencies = (
    ('CHF', "Swiss Francs"),
    ('EUR', "Euros"),
    )
    amount = models.FloatField();
    currency = models.CharField( max_length=3, choices=currencies, 
default='CHF' )

    def __str__(self):
    return "{} {}".format(self.amount, [ j[1] for i,j in
enumerate(self.currencies) if j[0] == self.currency][0] )
    def short(self):
    return "{} {}".format([ j[0] for i,j in
enumerate(self.currencies) if j[0] == self.currency][0], self.amount )
    def __add__(self, other):
    return AmountModel(amount=self.amount+other.amount,
currency=self.currency)

class DocumentModel(models.Model):
    class Meta:
    abstract = True
    tex = models.FileField(verbose_name = "TeX")
    pdf = models.FileField(verbose_name = "PDF")
    def generate_pdf( self ):
    return

class Invoice(AmountModel, DocumentModel):
    STATUS = (
    ("o", "open"), # initialized
    ("c", "complete"), # completed (no info missing)
    ("s","sent"), # sent
    ("p","pending"), # sent but money not yet received
    ("pd","paid") # paid and archived
    )
    client = models.ForeignKey( 'Client', on_delete=models.CASCADE )
    title = models.CharField( max_length=200 )
    status = models.CharField( max_length=2, choices = STATUS )
    number = models.IntegerField( blank=True )
    date_created = models.DateField( auto_now=True )
    date_sent = models.DateField( blank=True )
    date_paid = models.DateField( blank=True )

    @property
    def jobs(self):
    return Job.objects.filter( invoice=self )

    @property
    def expenses(self):
    return Expense.objects.filter( invoice=self )

    def __str__(self):
    if self.status.startswith('p'):
    return '%d %s'.format(self.number, self.title )
    return self.title

    def update_status(self):
    if (self.date_sent == None):
    self.status = STATUS[0][0]
    elif (self.date_paid == None):
    self.status = STATUS[1][0]
    else:
    self.status = STATUS[2][0]
    return

    def calculate_amount(self):
    amount = 0
    for o in [ self.jobs, self.expenses ].flatten:
    amount += o.amount
    self.amount = amount
    self.save()
    return

    def create_tex( self ):
    template_file = 'templates/invoice.tex'
    t = loader.get_template(template_file)
    context = {
        'title': self.title,
    }
    filename = '%d %s'.format(self.number, slugify(self.title) )
    self.tex.file = open(filename+'.tex', 'w')
    self.tex.file.write(smart_str( t.render(context) ))
    return

    def send_to_client( self ):
    return

# views.py
class CreateInvoice(CreateView):
    model = Invoice
    form_class = InvoiceForm
    template_name = 'standard_form.html'

    def get_initial(self):
    initial = super(CreateView, self).get_initial().copy()
    initial['title'] = "blablabla"
    amount = {'CHF': 0, 'EUR': 0}
    currency = self.jobs[0].worth.currency
    for j in self.jobs:
    amount[j.worth.currency] += j.worth.amount
    for a in amount.keys():
    if not amount[a] == 0:
    try:
    initial['value'] is None
    except KeyError:
    initial['currency'] = a
    initial['amount'] = amount[a]
    print(initial)
    return initial

    def post(self, request, *args, **kwargs):
    print("post()")
    req = request.POST.copy()
    req.pop('csrfmiddlewaretoken')
    self.jobs = Job.objects.filter(id__in=req.keys(),
client_id=kwargs['client_id'])
    return super(CreateView, self).post(request,*args,**kwargs)

# standard_form.html
{% extends 'main_form.html' %}
{% block formaction %}{{ formaction }}{% endblock %} {% block 'title' %}{{ 
title }}{% endblock %} {% block form %} {% for field in form %} 
  {{ field.errors }}
  {{ field.label_tag }}
  {{ field }}

{% endfor %}
{% endblock %}

--
You received this message because you are subscribed t

RE: unable to render initial data in ModelForm called through CreateView

2018-03-07 Thread Matthew Pava
Well, I see that you only set self.jobs in the post method in CreateInvoice.  
How are you seeing proper console output for get_initial when self.jobs is not 
even set in the get method?  Are you sure you are seeing exactly what you want 
to see?  Please double-check.  When presenting the form for the first time, it 
will use the get method on CreateInvoice.  Since you did not override it, it 
will use the default implementation.  You didn’t set self.jobs anywhere else 
but in the post method.

I also find this website helpful when dealing with class-based views:
https://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of furzihurzischleim
Sent: Wednesday, March 7, 2018 7:11 AM
To: Django users
Subject: Re: unable to render initial data in ModelForm called through 
CreateView

:)

Invoice Form is "just" a normal Modelform - nothing fancy added.

class InvoiceForm(forms.ModelForm):
class Meta:
model = Invoice
fields = '__all__'
def __init__(self,*args,**kwargs):
print("InvoiceForm.__init__();;;")
#print( self)
print( args)
print( kwargs)
return super(InvoiceForm, self).__init__( *args, **kwargs )

Am Dienstag, 6. März 2018 18:08:33 UTC+1 schrieb Matthew Pava:
Let's see InvoiceForm.
Also, it doesn't make much of a different, but I wouldn't call copy on the 
super.get_initial() method.


-Original Message-
From: django...@googlegroups.com 
[mailto:django...@googlegroups.com] On Behalf Of Gabriel Wicki
Sent: Sunday, March 4, 2018 2:48 PM
To: django...@googlegroups.com
Subject: unable to render initial data in ModelForm called through CreateView

hello list

i ran into some weird stuff and neither i nor 2 gentle folks down at the 
irc-chat could find any obvious problems. task should have been easy:
calculate some special initial data and present it as initials in a form. the 
form is showed correctly, and the right values are printed in console.. and, of 
course, there is no error raised..

thank you for any hints! i've been stuck here


gabriel




# models.py
class AmountModel(models.Model):
class Meta:
abstract = True
currencies = (
('CHF', "Swiss Francs"),
('EUR', "Euros"),
)
amount = models.FloatField();
currency = models.CharField( max_length=3, choices=currencies, 
default='CHF' )

def __str__(self):
return "{} {}".format(self.amount, [ j[1] for i,j in
enumerate(self.currencies) if j[0] == self.currency][0] )
def short(self):
return "{} {}".format([ j[0] for i,j in
enumerate(self.currencies) if j[0] == self.currency][0], self.amount )
def __add__(self, other):
return AmountModel(amount=self.amount+other.amount,
currency=self.currency)

class DocumentModel(models.Model):
class Meta:
abstract = True
tex = models.FileField(verbose_name = "TeX")
pdf = models.FileField(verbose_name = "PDF")
def generate_pdf( self ):
return

class Invoice(AmountModel, DocumentModel):
STATUS = (
("o", "open"), # initialized
("c", "complete"), # completed (no info missing)
("s","sent"), # sent
("p","pending"), # sent but money not yet received
("pd","paid") # paid and archived
)
client = models.ForeignKey( 'Client', on_delete=models.CASCADE )
title = models.CharField( max_length=200 )
status = models.CharField( max_length=2, choices = STATUS )
number = models.IntegerField( blank=True )
date_created = models.DateField( auto_now=True )
date_sent = models.DateField( blank=True )
date_paid = models.DateField( blank=True )

@property
def jobs(self):
return Job.objects.filter( invoice=self )

@property
def expenses(self):
return Expense.objects.filter( invoice=self )

def __str__(self):
if self.status.startswith('p'):
return '%d %s'.format(self.number, self.title )
return self.title

def update_status(self):
if (self.date_sent == None):
self.status = STATUS[0][0]
elif (self.date_paid == None):
self.status = STATUS[1][0]
else:
self.status = STATUS[2][0]
return

def calculate_amount(self):
amount = 0
for o in [ self.jobs<http://self.jobs>, self.expenses ].flatten:
amount += o.amount
self.amount = amount
self.save()
return

def create_tex( self ):
template_file = 'templates/invoice.tex'
t = loader

RE: unable to render initial data in ModelForm called through CreateView

2018-03-07 Thread Matthew Pava
Correct, post is for POST, get is for GET.
When a form is POSTed successfully, the user is redirected to another URL, 
typically a success page or something of your choosing.
So after your POST, if you are simply redirecting back to this CreateView, you 
no longer have access to the invoice that you just created in this view.  You 
are creating a completely new invoice using the GET method.
Maybe you mean to be creating an UpdateView with this new information about 
self.jobs?

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of furzihurzischleim
Sent: Wednesday, March 7, 2018 12:10 PM
To: Django users
Subject: Re: unable to render initial data in ModelForm called through 
CreateView

thanks for the link, i was aware of that but was unable to find my error 
(that's why i turned to irc, and then to the list)..

it is true self.jobs is set from the post() method. that's because the 
CreateView should be called if there are jobs selected in a POST-form. so 
post() sets self.jobs which get processed (and summed to initial['amount'] and 
initial['currency']) in get_initial(), which itself is printed to console 
correctly. it then instantiated a form, which gets the right arguments (initial 
dict) with the right values. but they won't show up :(

just for clarification: post() gets called if the request uses POST-method, and 
get() gets called on GET-requests, right?

i know this is more of a beginner issue, but i'm unable to get further in my 
work at this point. thanks for your time and your advice!


Am Mittwoch, 7. März 2018 18:44:40 UTC+1 schrieb Matthew Pava:
Well, I see that you only set self.jobs<http://self.jobs> in the post method in 
CreateInvoice.  How are you seeing proper console output for get_initial when 
self.jobs<http://self.jobs> is not even set in the get method?  Are you sure 
you are seeing exactly what you want to see?  Please double-check.  When 
presenting the form for the first time, it will use the get method on 
CreateInvoice.  Since you did not override it, it will use the default 
implementation.  You didn’t set self.jobs<http://self.jobs> anywhere else but 
in the post method.

I also find this website helpful when dealing with class-based views:
https://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/


From: django...@googlegroups.com 
[mailto:django...@googlegroups.com] On Behalf Of furzihurzischleim
Sent: Wednesday, March 7, 2018 7:11 AM
To: Django users
Subject: Re: unable to render initial data in ModelForm called through 
CreateView

:)

Invoice Form is "just" a normal Modelform - nothing fancy added.

class InvoiceForm(forms.ModelForm):
class Meta:
model = Invoice
fields = '__all__'
def __init__(self,*args,**kwargs):
print("InvoiceForm.__init__();;;")
#print( self)
print( args)
print( kwargs)
return super(InvoiceForm, self).__init__( *args, **kwargs )

Am Dienstag, 6. März 2018 18:08:33 UTC+1 schrieb Matthew Pava:
Let's see InvoiceForm.
Also, it doesn't make much of a different, but I wouldn't call copy on the 
super.get_initial() method.


-Original Message-
From: django...@googlegroups.com<mailto:django...@googlegroups.com> 
[mailto:django...@googlegroups.com] On Behalf Of Gabriel Wicki
Sent: Sunday, March 4, 2018 2:48 PM
To: django...@googlegroups.com<mailto:django...@googlegroups.com>
Subject: unable to render initial data in ModelForm called through CreateView

hello list

i ran into some weird stuff and neither i nor 2 gentle folks down at the 
irc-chat could find any obvious problems. task should have been easy:
calculate some special initial data and present it as initials in a form. the 
form is showed correctly, and the right values are printed in console.. and, of 
course, there is no error raised..

thank you for any hints! i've been stuck here


gabriel




# models.py
class AmountModel(models.Model):
class Meta:
abstract = True
currencies = (
('CHF', "Swiss Francs"),
('EUR', "Euros"),
)
amount = models.FloatField();
currency = models.CharField( max_length=3, choices=currencies, 
default='CHF' )

def __str__(self):
return "{} {}".format(self.amount, [ j[1] for i,j in
enumerate(self.currencies) if j[0] == self.currency][0] )
def short(self):
return "{} {}".format([ j[0] for i,j in
enumerate(self.currencies) if j[0] == self.currency][0], self.amount )
def __add__(self, other):
return AmountModel(amount=self.amount+other.amount,
currency=self.currency)

class DocumentModel(models.Model):
class Meta:
abstract = True
tex = models.FileField(verbose_name = "TeX")
pdf = mod

RE: Fetching next and/or prior objects given an arbitrary ordering

2018-03-15 Thread Matthew Pava
Did you look at the Subquery expression?
https://docs.djangoproject.com/en/2.0/ref/models/expressions/#subquery-expressions


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Bernd Wechner
Sent: Thursday, March 15, 2018 1:57 AM
To: Django users
Subject: Re: Fetching next and/or prior objects given an arbitrary ordering

Well the silence was stunning, so I pottered along and have a working solution. 
Alas I lean on a raw() call which I'd rather not. If there is any way to do 
this in the ORM I'd love to know. Otherwise I'm probably off to submit it as a 
feature request. The Window functions will all suffer this utility problem, 
that to use them meaningfully it may often be necessary to nest SELECTs. Here's 
a working neighbour fetcher:
def get_neighbor_pks(model, pk, filterset=None, ordering=None):
'''
Given a model and pk that identify an object (model instance) will, given 
an ordering
(defaulting to the models ordering) and optionally a filterset (from 
url_filter), will
return a tuple that contains two PKs that of the prior and next neighbour 
in the list
either of all objects by that ordering or the filtered list (if a filterset 
is provided)
:param model:The model the object is an instance of
:param pk:   The primary key of the model instance being considered
:param filterset:An optional filterset (see 
https://github.com/miki725/django-url-filter)
:param ordering: An optional ordering (otherwise default model ordering 
is used). See: 
https://docs.djangoproject.com/en/2.0/ref/models/options/#ordering
'''
# If a filterset is provided ensure it's of the same model as specified 
(consistency).
if filterset and not filterset.Meta.model == model:
return None

# Get the ordering list for the model (a list of fields
# See: https://docs.djangoproject.com/en/2.0/ref/models/options/#ordering
if ordering is None:
ordering = model._meta.ordering

order_by = []
for f in ordering:
if f.startswith("-"):
order_by.append(F(f[1:]).desc())
else:
order_by.append(F(f).asc())

# Define the window functions for each neighbour
window_lag = Window(expression=Lag("pk"), order_by=order_by)
window_lead = Window(expression=Lead("pk"), order_by=order_by)

# Get a queryset annotated with neighbours. If annotated attrs clash with 
existing attrs an exception
# will be raised: https://code.djangoproject.com/ticket/11256
try:
# If a non-empty filterset is supplied, respect that
if filterset and filterset.filter:
qs = filterset.filter() | model.objects.filter(pk=pk).distinct()
# Else we just use all objects
else:
qs = model.objects

# Now annotate the querset with the prior and next PKs
qs = qs.annotate(neighbour_prior=window_lag, neighbour_next=window_lead)
except:
return None

# Finally we need some trickery alas to do a query on the queryset! We 
can't add this WHERE
# as a filter because the LAG and LEAD Window functions fail then, they are 
emoty because
# there is no lagger or leader on the one line result! So we have to run 
that query on the
# whole table.then extract form the result the one line we want! Wish I 
could find a way to
# do this in the Django ORM not with a raw() call.
ao = model.objects.raw("SELECT * FROM ({}) ao WHERE 
{}=%s".format(str(qs.query), model._meta.pk.name),[pk])

if ao:
return (ao[0].neighbour_prior,ao[0].neighbour_next)
else:
raise None



On Wednesday, 14 March 2018 06:28:55 UTC+11, Bernd Wechner wrote:
Hmmm, really stuck on this. Can find no way of selecting from a select in the 
ORM. The whole premise seems be to start from model.objects and add SQL clauses 
with filter, annotate and other methods. But a QuerySet is not a model and 
queryset.objects doesn't exist, and queryset.filter just adds a where clause to 
the select on the original model not on the result of the queryset. It's almost 
as if we need a way to cast a queryset as a virtual model in the style of:
def get_prior(model, pk):
# Get the ordering list for the model (a list of fields
# See: https://docs.djangoproject.com/en/2.0/ref/models/options/#ordering
ordering = model._meta.ordering

order_by = []
for f in ordering:
if f.startswith("-"):
order_by.append(F(f[1:]).desc())
else:
order_by.append(F(f).asc())

my_queryset = model.objects.annotate(prior=Window(expression=Lag("pk"), 
order_by=order_by))

my_result = Model(my_queryset).objects.filter(pk=pk)

That last line is the crux of the issue.I see no way of writing this. When 
doing this:

my_result = my_queryset.filter(pk=pk)

The WHERE clause ends up on the select in in my_querset. we want to wrap the 
whole of my_queryset with
select * from my_queryset where pk=pk

But

RE: Question about Getting URL segment into a View

2018-03-16 Thread Matthew Pava
Use self.kwargs.get(‘gwpk’)
https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-display/#dynamic-filtering


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of RisenFenix
Sent: Friday, March 16, 2018 7:55 AM
To: Django users
Subject: Question about Getting URL segment into a View

I am a newby to Django (2.0) and need some assistance, please.  I have a list 
of Grocery Wholesale Vendors in one model and their Contacts in another with 
one to many join.

The Model...

from django.conf import settings
from django.db import models
from django.urls import reverse

[...]

#Grocery Wholesale Table
class GroceryWholesale(models.Model):
grocery_wholesaler = models.CharField(max_length=150)
grocery_wholesaler_active = models.BooleanField(default=True)

def __str__(self):
"""A string representation of the model."""
return self.grocery_wholesaler[:50]

class Meta:
verbose_name_plural = "Grocery Wholesalers"

#Grocery Wholesale Contacts Table
class GroceryWholesaleContacts(models.Model):
grocery_wholesaler = models.ForeignKey(GroceryWholesale, 
on_delete=models.CASCADE)
contact_name = models.CharField(max_length=150, null=True)
contact_phone = models.CharField(max_length=75,null=True)
contact_mobile = models.CharField(max_length=75,null=True)
contact_fax = models.CharField(max_length=75, null=True)
contact_email = models.CharField(max_length=150, null=True)
contact_notes = models.CharField(max_length=200, null=True)
contact_active = models.BooleanField(default=True)

def __str__(self):
"""A string representation of the model."""
return self.contact_name[:50]

class Meta:
verbose_name_plural = "Grocery Wholesaler Contacts"

Then in my URLs I have

from django.urls import path
from . import views

urlpatterns = [
path('gwlist', views.GroceryWholesalersListView.as_view(), 
name='grocerywholesalers'),
path('gwclist//', 
views.GroceryWholesalersContactsListView.as_view(), 
name='grocerywholesalerscontacts'),
]

My Views I have

from django.shortcuts import render
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import ListView, DetailView
from django.views.generic import TemplateView
from django.urls import reverse
from django.http import HttpResponse
from . import models
from .models import GroceryWholesale, GroceryWholesaleContacts

# Create your views here.
class GroceryWholesalersListView(ListView):
model = models.GroceryWholesale
context_object_name = 'grocery_wholesalers'
template_name = 'grocery_wholesaler_list.html'
ordering = ['grocery_wholesaler']

class GroceryWholesalersContactsListView(ListView):
model = models.GroceryWholesaleContacts
context_object_name = 'grocery_contacts'
template_name = 'grocery_wholesaler_contacts_list.html'
ordering = ['contact_name']
def get_queryset(self):
return 
GroceryWholesaleContacts.objects.filter(grocery_wholesaler_id=request.gwpk)

It's the part in Red I am having trouble with.  If I hand type a primary key 
for the Grocery Wholesaler I get the correct filtered list of contacts
IE
return GroceryWholesaleContacts.objects.filter(grocery_wholesaler_id='90') and 
that pulls up the Grocery Wholesaler contacts filtered to ONLY show the ones 
belonging to grocery_wholesale_id #90

BUT I am trying to figure out how to pull the PK code dynamically from the URL 
instead and I can't figure it out or what it is called to google for help.  My 
URL looks like this...  http://127.0.0.1:8000/clients/gwclist/90/

Any help is greatly appreciated.  I hope I explained this correctly.
--
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/3a144ad0-ee41-406e-8eb6-532c001ac152%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/94862a184dfe4b14bd71f29a933bf95d%40ISS1.ISS.LO

RE: Fetching next and/or prior objects given an arbitrary ordering

2018-03-16 Thread Matthew Pava
Hi Bernd,
Indeed, I did not look closely at what was happening.  Definitely add a feature 
request.  I sincerely believe that if we would implement the Subquery object as 
a CTE, it would resolve these situations without much changing anything else.  
https://code.djangoproject.com/ticket/28919
Thanks,
Matthew

I would like to see something like this:
cte = Subquery(model.objects.annotate(prior=Window(expression=Lag("pk"), 
order_by=order_by)).annotate(next=Window(expression=Lead("pk"), 
order_by=order_by)))
result = model.objects.annotate(id=cte["id"], prior=cte["prior"], 
next=cte["next"]).filter(pk=some_id)

would produce something like this

WITH cte(id, prior, next) AS (
SELECT id, LAG(id, 1) OVER (ORDER BY ) AS prior, 
LEAD(id 1) OVER (ORDER BY ) AS next
FROM 
)
SELECT cte.id, cte.prior, cte.next
FROM  JOIN cte ON cte.id=.id
WHERE id=

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Bernd Wechner
Sent: Thursday, March 15, 2018 4:48 PM
To: Django users
Subject: Re: Fetching next and/or prior objects given an arbitrary ordering

Mathtew,

Yes I most certainly have. I use them elsewhere. i love SubQuery. But I can 
only find examples and documentation about using them in the WHERE clause (or a 
filer() arguments). If you can write me an example of how one might be used in 
the FROM clause as in my example below I'd be indebted. It's a challenge 
indeed, as the FROM clause in the ORM is dictated by the model in the syntax 
model.objects.filter(), where filter() defines the WHERE clause and model the 
FROM clause. How can a SubQuiery be put into place there, in the FROM clause?

I would dearly love to learn that was possible and I've overlooked it somehow.

Regards,

Bernd.

On Friday, 16 March 2018 00:55:09 UTC+11, Matthew Pava wrote:
Did you look at the Subquery expression?
https://docs.djangoproject.com/en/2.0/ref/models/expressions/#subquery-expressions


From: django...@googlegroups.com 
[mailto:django...@googlegroups.com] On Behalf Of Bernd Wechner
Sent: Thursday, March 15, 2018 1:57 AM
To: Django users
Subject: Re: Fetching next and/or prior objects given an arbitrary ordering

Well the silence was stunning, so I pottered along and have a working solution. 
Alas I lean on a raw() call which I'd rather not. If there is any way to do 
this in the ORM I'd love to know. Otherwise I'm probably off to submit it as a 
feature request. The Window functions will all suffer this utility problem, 
that to use them meaningfully it may often be necessary to nest SELECTs. Here's 
a working neighbour fetcher:
def get_neighbor_pks(model, pk, filterset=None, ordering=None):
'''
Given a model and pk that identify an object (model instance) will, given 
an ordering
(defaulting to the models ordering) and optionally a filterset (from 
url_filter), will
return a tuple that contains two PKs that of the prior and next neighbour 
in the list
either of all objects by that ordering or the filtered list (if a filterset 
is provided)
:param model:The model the object is an instance of
:param pk:   The primary key of the model instance being considered
:param filterset:An optional filterset (see 
https://github.com/miki725/django-url-filter)
:param ordering: An optional ordering (otherwise default model ordering 
is used). See: 
https://docs.djangoproject.com/en/2.0/ref/models/options/#ordering
'''
# If a filterset is provided ensure it's of the same model as specified 
(consistency).
if filterset and not filterset.Meta.model == model:
return None

# Get the ordering list for the model (a list of fields
# See: https://docs.djangoproject.com/en/2.0/ref/models/options/#ordering
if ordering is None:
ordering = model._meta.ordering

order_by = []
for f in ordering:
if f.startswith("-"):
order_by.append(F(f[1:]).desc())
else:
order_by.append(F(f).asc())

# Define the window functions for each neighbour
window_lag = Window(expression=Lag("pk"), order_by=order_by)
window_lead = Window(expression=Lead("pk"), order_by=order_by)

# Get a queryset annotated with neighbours. If annotated attrs clash with 
existing attrs an exception
# will be raised: https://code.djangoproject.com/ticket/11256
try:
# If a non-empty filterset is supplied, respect that
if filterset and filterset.filter:
qs = filterset.filter() | model.objects.filter(pk=pk).distinct()
# Else we just use all objects
else:
qs = model.objects

# Now annotate the querset with the prior and next PKs
qs = qs.annotate(neighbour_prior=window_lag, neighbour_next=window_lead)
except:
return None

# Finally we need some trickery alas 

RE: how to hide filed use empty_value_display

2018-03-29 Thread Matthew Pava
Maybe you are looking for “empty_label=None”?
https://docs.djangoproject.com/en/2.0/ref/forms/fields/#django.forms.ModelChoiceField.empty_label


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of shawn...@gmail.com
Sent: Wednesday, March 28, 2018 6:09 AM
To: Django users
Subject: how to hide filed use empty_value_display

Hi Everyone!

Is there any method to do not display the blank field use 'empty_value_display'?

I mean, only appear those fields with values but not show those fields without 
values.
--
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/67b5c7a4-e929-472e-8ff3-53f24710f13e%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/fa3f26e9e60a486bb88f849e695e0808%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Get fields annotated to a QuerySet

2018-04-05 Thread Matthew Pava
I have a QuerySet that I annotated fields based on some conditional logic, and 
then I pass that QuerySet to another function.  In that function, I'd like to 
retrieve a list of all the annotated fields on the QuerySet.  Is there any way 
to do that?

-- 
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/04c7bc944399442b9c15d5fd45f6997b%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Need Help With integrating Python Scripts with Django Frame Work

2018-04-16 Thread Matthew Pava
Add a new view that returns the files.  Connect the “Download” button to the 
URL to that view.
Your view should return an HttpResponse object.  For instance, I use this for 
the user to download PDF versions of forms:

response = HttpResponse(pdf_contents, content_type='application/pdf')
response['Content-Disposition'] = "%sfilename=%s" % ('attachment; ' if download 
else '', filename)
return response

For pptx, your content_type would be:

'.pptx': 
'application/vnd.openxmlformats-officedocument.presentationml.presentation',


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Balu Nanduri
Sent: Monday, April 16, 2018 2:48 PM
To: Django users
Subject: Need Help With integrating Python Scripts with Django Frame Work

Hi,
 I am working on a project where I have to communicate with Tableau 
server and generate pptx with the images downloaded. I have a working script to 
do this piece, currently the script generates pptx and stores it to my local 
filesystem.

Now I would like to create a web page which would accept necessary input from 
users and should trigger the script which generates pptx and then downloads the 
files to the user's browser.

I had set up DJANGO environment of the same but not getting how to call this 
script from the web page so, could anyone help me out with a overview on how 
can I call my working script on click of a button and download the files 
generated by the script.

Thanks & Regards
Balu
--
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/b5471890-0cd8-4ee7-a7c5-c43840590a4d%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/02eb6190ff484840b8729f146bb3e166%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Adding stored procedures

2018-04-18 Thread Matthew Pava
Hi Chris,
SQL Server is not one of the databases that Django supports out of the box.  
There are third party packages available, though, but I haven’t tested any of 
them with recent versions.
Saying that, you can create views in your database backend.  In your migrations 
file, use the RunSQL operation.
https://docs.djangoproject.com/en/2.0/ref/migration-operations/#runsql

In your models file, change the Meta option, managed, to False.
https://docs.djangoproject.com/en/2.0/ref/models/options/#managed

Good luck!

As for stored procedures and functions, I haven’t worked enough with those 
mixed in with Django to give you much guidance except to do some more searching 
on the web.  And I would also advise against using them so that you can keep 
your code in your Django project.  I haven’t found a need for them myself while 
using Django.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Chris Wedgwood
Sent: Wednesday, April 18, 2018 1:50 AM
To: django-users@googlegroups.com
Subject: Adding stored procedures

Hi All

I am using SQL SERVER in my latest django project and I am going to be using 
some stored procedures.

My question is about how to go about deploying stored procedure changes with 
django. I have looked through the migrations documentation which looks very 
specific to model changes.

Has anyone had experience of having to create other things such a stored 
procedures/views/functions?

thanks
Chris




--
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/CACQBJYU5CDhCrP7cNRpzp7fRDr1pyf48css-EaVW%3Drj65SmEsg%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/58f5f935832647b0afd58ac5105b45f0%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Adding stored procedures

2018-04-19 Thread Matthew Pava
Hi Chris,
The migrations will be run whenever you execute the migrate command.  When I 
want to make changes to an unmanaged model, in the next migration file I add a 
DROP statement to RunSQL, and then the new code to generate the VIEW.  I 
haven’t attempted reversing a migration, though.  I try to test with the new 
migration before deploying to production.
Best wishes,
Matthew

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Chris Wedgwood
Sent: Thursday, April 19, 2018 9:02 AM
To: Django users
Subject: Re: Adding stored procedures

Thanks Matthew

I probably need to think about this some more

I think using runsql will work. Do you know if you can set migrations to be 
rerunnable? It would be useful to be able to change something like a stored 
procedure and then it gets dropped and recreated each deployment

Saying that the stored procedure is going to be used for an import task that 
isn't actually related to Django so probably needs to be deployed  by another 
mechanism and I should leave migrations for only DJango specific changes

thanks
Chris



On Wednesday, 18 April 2018 07:50:52 UTC+1, Chris Wedgwood wrote:
Hi All

I am using SQL SERVER in my latest django project and I am going to be using 
some stored procedures.

My question is about how to go about deploying stored procedure changes with 
django. I have looked through the migrations documentation which looks very 
specific to model changes.

Has anyone had experience of having to create other things such a stored 
procedures/views/functions?

thanks
Chris




--
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/20a5ed5a-97f4-413b-8700-58606b781a2f%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/373c82f3da11492182afcb2ee961d0fd%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Use self-increasing arguments in numeric for-loop in Django

2018-04-19 Thread Matthew Pava
Is there something stopping you from using this construct?
{% for item in graphobject %}

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Jani Tiainen
Sent: Thursday, April 19, 2018 11:29 AM
To: django-users@googlegroups.com
Subject: Re: Use self-increasing arguments in numeric for-loop in Django

Hi. Django templating language isn't programming language. It can't do that. 
You need to prepare data suitable for displaying in your view.


On Thu, Apr 19, 2018 at 7:01 PM, 
mailto:shawn...@gmail.com>> wrote:

I am currently working on django.

I have a list of values which stored in 'graphobject', and 'metarange' is 
defined as range(0,59). In that case, how could I use numbers as argument to 
display the value stored in graphobject? I tried using following codes but it 
doesn't work



{% for i in metarange %}

{% if graphobject.i != '' %}

{{ graphobject.i }}

{% endif %}

{% endfor %}



Please tell me how could I do 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/931f17b7-4cca-4b11-9aae-7e3092732dd3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...
--
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/CAHn91odiq4Cu3fvcTowWW5n11oUSppkA-scNi8WRR4xOVYN38g%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/8aaed14e428848f68d5c11a203abecb4%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Use self-increasing arguments in numeric for-loop in Django

2018-04-20 Thread Matthew Pava
You have a list of values.  Use the Pythonic way to iterating over a list, 
which does not involve using indices.

{% for o in graphobject %}
{{ o }}
{{ o.subfield }}
{% endfor %}


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Bill Torcaso
Sent: Friday, April 20, 2018 8:50 AM
To: Django users
Subject: Re: Use self-increasing arguments in numeric for-loop in Django


I an new-ish to Django, and I ask this to hear from more experienced users 
whether this would work at all, and whether it would be considered a good or 
bad practice.

Goal: given an object and an integer index, retrieve the sub-object at that 
index within the incoming object.

Method:  Write a custom tag.  Provide the tag with the larger object, and the 
integer index.  Return the sub-object at that index (or whatever field(s) are 
needed).

Usage:


  {% for i in metarange %}

{% graphobject_get_by_index graphobject {{ i }} %}

  {% endfor %}


In this particular case, there is an issue about whether the sub-object can be 
null, for some definition of null.  There are various ways to deal with that.

Again, I am new-ish to Django.  Is there a similar approach in which 
'get_by_index' is a method on class Graphobject, such that this would work?

{% graphobject.get_by_index {{ i }} %}

Thanks for any explanation about these approaches.


On Thursday, April 19, 2018 at 12:01:37 PM UTC-4, 
shaw...@gmail.com wrote:

I am currently working on django.

I have a list of values which stored in 'graphobject', and 'metarange' is 
defined as range(0,59). In that case, how could I use numbers as argument to 
display the value stored in graphobject? I tried using following codes but it 
doesn't work



{% for i in metarange %}

{% if graphobject.i != '' %}

{{ graphobject.i }}

{% endif %}

{% endfor %}



Please tell me how could I do 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/9c162dd2-201b-4370-bac0-f3afb3db163a%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/62ae273ee7634261ad5421b0809c28cc%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: django.db.migrations.exceptions.NodeNotFoundError while upgrading django

2018-04-23 Thread Matthew Pava
Did you try running makemigrations first?

./manage.py makemigrations

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Akhi
Sent: Monday, April 23, 2018 1:38 AM
To: Django users
Subject: django.db.migrations.exceptions.NodeNotFoundError while upgrading 
django

I am upgrading my django project from django1.5 to django1.11.10. while 
upgrading when I run ./manange.py migrate I am getting 
django.db.migrations.exceptions.NodeNotFoundError

django.db.migrations.exceptions.NodeNotFoundError: Migration 
account.0004_auto_20180419_1309 dependencies reference nonexistent parent node 
(u'admin', 
u'0003_advertisements_alignedcourses_api_integration_appreciation_certificate_company_company_types_contrib')


I could not find any migration files from my project and I followed some of the 
solution which I found in internet.

django.db.migrations.exceptions.NodeNotFoundError Migration authentication 
nonexistent parent 
node

Can't get rid of "nonexistent parent node" in django 
1.11

I reinstalled django.Deleted all .pyc files. deleted all migrations files. 
Still I am getting the same error.Please help me and can you please explain why 
it is happening?

I have attached my project structure.

[https://lh3.googleusercontent.com/-T8myMeiuk7E/Wt1-7clrS6I/FMA/H4HvwfJCjjYrBgJbXOpuduuuIZ0r1q2gACLcBGAs/s1600/Untitled%2BDiagram.jpg]





admin/apps.py



class AdminConfig(AppConfig):

name = 'apps.admin'

label = 'admin_app'

account/apps.py

class AccountConfig(AppConfig):
name = 'account'
label = 'account_app'

and I have mentioned meta properties for all the admin app models.

class Meta:
'''
Meta properties for this model
'''
app_label = 'admin_app'




--
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/0d5e63a8-0281-4e53-ab18-8f56030b2787%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/be2f4ffa5fe245ad8217483b00c4f68c%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Cannot find template files for 1.11

2018-04-23 Thread Matthew Pava
DIRS does not have the path that you indicated it has.  Try changing it.
DIRS = ['designer/template/designer/']


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of John Wilkinson
Sent: Monday, April 23, 2018 7:47 AM
To: Django users
Subject: Cannot find template files for 1.11

I am having trouble setting up django to find my template file I have created.

The settings.py has, among other sections, the following:


INSTALLED_APPS = [
'designer.apps.DesignerConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]


TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': 
["/home/john/git/primaryWindingsCalculator/windingCalculator/designer/template"],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

If I take the entry out of the DIRS array, django won't be able to find my 
template file, I have put in a directory:

designer/template/designer/

I thought that if my app was in the INSTALLED_APPS list, then it would look in 
there dor my templates, and in
designer/static/designer/

for all static files, that it can't find also by the way.

Any help much appreciated.

Many thanks,
John.
--
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/f86815a6-9d73-4ede-a65d-f6c62919e8eb%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/0c94e784ecb34622acfc144c397afedd%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Cannot find template files for 1.11

2018-04-23 Thread Matthew Pava
Actually, I just use this construct:
'DIRS': [
# insert your TEMPLATE_DIRS here
os.path.join(BASE_DIR, 'project_name', 'templates'),
],


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of John Wilkinson
Sent: Monday, April 23, 2018 7:47 AM
To: Django users
Subject: Cannot find template files for 1.11

I am having trouble setting up django to find my template file I have created.

The settings.py has, among other sections, the following:


INSTALLED_APPS = [
'designer.apps.DesignerConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]


TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': 
["/home/john/git/primaryWindingsCalculator/windingCalculator/designer/template"],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

If I take the entry out of the DIRS array, django won't be able to find my 
template file, I have put in a directory:

designer/template/designer/

I thought that if my app was in the INSTALLED_APPS list, then it would look in 
there dor my templates, and in
designer/static/designer/

for all static files, that it can't find also by the way.

Any help much appreciated.

Many thanks,
John.
--
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/f86815a6-9d73-4ede-a65d-f6c62919e8eb%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/ef4cb7c15a2045a3b1ba3c44d3c76922%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Crazy Idea: OOP for "Hyperlink"

2018-04-26 Thread Matthew Pava
I’ve been thinking about your idea, and I wonder if there could instead be some 
kind of widget for URL objects (or views).

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of guettli
Sent: Thursday, April 26, 2018 8:34 AM
To: Django users
Subject: Re: Crazy Idea: OOP for "Hyperlink"



Am Mittwoch, 25. April 2018 17:29:36 UTC+2 schrieb Jani Tiainen:
Hi.

Most probably you get there by creating custom template tag and bunch of other 
code.

It would be easier to grasp your idea if you have some kind of an 
implementation to reference.

Or is there something that stops you from proceeding?


Yes, there is something that stops me: work, family, friends, tennis, sleeping. 
With other words "time".

Nevertheless, even if I had time, I would do asking, talking and thinking for 
some days before taking the keyboard :-)

Regards,
  Thomas
--
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/b5c3f2db-f664-4855-a63c-349fb04d398f%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/612379414d7f4cf7a2c8aa1185decab9%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Dynamically altering a (ForeignKey) ModelChoiceField’s values

2018-04-27 Thread Matthew Pava
In the form’s __init__ method, you’ll have to modify the queryset of the field.

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields[‘choretime’].queryset |= 
ChoiceTime.objects.filter(pk=self.instance.pk)

I hope that helps!

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Jim Illback
Sent: Friday, April 27, 2018 11:16 AM
To: Django users
Subject: Re: Dynamically altering a (ForeignKey) ModelChoiceField’s values

To make this easier, here is just a simple the question.

Does Django give a method that can be overridden while processing a form which 
has access to the incoming URL parameters and precedes the display of the 
form’s fields, specifically being able to alter the fields’s query set before 
it is displayed?

Thanks for any help to answer this question.

Jim Illback


On Apr 25, 2018, at 10:41 AM, Jim Illback 
mailto:subaru...@hotmail.com>> wrote:

I wondered if anyone has had to alter the queryset behind a model form’s 
foreign key field which presents as a model choice field?
Briefly, I have a client attribute table with the foreign key to a chore/time 
table. For an add of the client attribute table, I want to limit entries to 
unassigned chore/time combinations only. This works perfectly during my 
CreateView. Here are some extracts to show specifics:
Models.py:
class ChoreTime(models.Model):
chore = models.ForeignKey(Chore, on_delete=models.CASCADE)
time = models.ForeignKey(TimePeriod, on_delete=models.CASCADE)
priority = models.BooleanField(default=False)
…
class Checkin(models.Model):
client = models.ForeignKey(Client, on_delete=models.CASCADE)
choretime = models.ForeignKey(ChoreTime, on_delete=models.CASCADE)
…
Forms.py:
class CheckinForm(forms.ModelForm):
assigned_qs = 
Checkin.objects.values(‘choretime').filter(choretime_id__isnull=False)
choretime = 
forms.ModelChoiceField(queryset=ChoreTime.objects.exclude(pk__in=assigned_qs))
…
However, I cannot get the any design to work on an UpdateView form. Using the 
same form as above, the current value does not even show up – it is blank – 
because, of course, that entry is already assigned so is excluded.
What I’d like is to have the above exclusions BUT be able to also add in the 
single entry assigned to the client being updated – so the entry will show that 
specific assignment (as well as limiting any possible change options to 
unassigned values - just like on the Create).
The problems with various approaches I’ve tried are:

1. Anything done before the form is fully assembled won’t have the existing 
form’s Checkin ID value (which is part of the URL, just BTW). This is needed to 
look up and add the existing entry. So, having a database view won’t work 
without being able to communicate the existing person’s assignment ID to the 
view. Similarly, using an override queryset on the form, like done above for 
the Create, needs that ID, too.

2. If I do the queries in the class's GET method routine as ORM objects, I 
must use UNION (a union of the exclusions as above plus the existing update 
client’s assignment). That union option keeps giving an error that one of the 
ORM querysets is not a queryset. However, they are both using 
“.objects.filter…”. It seems like complex queries don’t work with the 
union command. If I use raw SQL, the query works but the assignment to the 
choretime field’s queryset fails.
Does anyone have experience with this sort of behavior and be willing to give 
guidance?

--
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/F0B95720-C669-4CE5-912E-5167E3B89DFE%40hotmail.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/C42DA3B1-C882-4889-995B-49580840F539%40hotmail.com

RE: Dynamically altering a (ForeignKey) ModelChoiceField’s values

2018-04-27 Thread Matthew Pava
That ID in the URL should be taken care of in the view, not the form.  You pass 
the object in as keyword instance to instantiate the form.  How are you 
defining your form in the view?

Typically, you would do something like this:

instance = CheckIn.objects.get(pk=self.kwargs.get(‘pk’))
form = CheckInForm(request.POST or None, instance=instance)

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Jim Illback
Sent: Friday, April 27, 2018 11:33 AM
To: Django users
Subject: Re: Dynamically altering a (ForeignKey) ModelChoiceField’s values

I also need to have the specific ID specified in the URL, so that is the other 
part needed. I’ve successfully done your suggestion for CreateView. Now, I just 
can’t seem to get UpdateView to work properly.

Thanks much!
Jim


On Apr 27, 2018, at 9:20 AM, Matthew Pava 
mailto:matthew.p...@iss.com>> wrote:

In the form’s __init__ method, you’ll have to modify the queryset of the field.

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields[‘choretime’].queryset |= 
ChoiceTime.objects.filter(pk=self.instance.pk)

I hope that helps!

From: django-users@googlegroups.com<mailto:django-users@googlegroups.com> 
[mailto:django-users@googlegroups.com] On Behalf Of Jim Illback
Sent: Friday, April 27, 2018 11:16 AM
To: Django users
Subject: Re: Dynamically altering a (ForeignKey) ModelChoiceField’s values

To make this easier, here is just a simple the question.

Does Django give a method that can be overridden while processing a form which 
has access to the incoming URL parameters and precedes the display of the 
form’s fields, specifically being able to alter the fields’s query set before 
it is displayed?

Thanks for any help to answer this question.

Jim Illback



On Apr 25, 2018, at 10:41 AM, Jim Illback 
mailto:subaru...@hotmail.com>> wrote:

I wondered if anyone has had to alter the queryset behind a model form’s 
foreign key field which presents as a model choice field?
Briefly, I have a client attribute table with the foreign key to a chore/time 
table. For an add of the client attribute table, I want to limit entries to 
unassigned chore/time combinations only. This works perfectly during my 
CreateView. Here are some extracts to show specifics:
Models.py:
class ChoreTime(models.Model):
chore = models.ForeignKey(Chore, on_delete=models.CASCADE)
time = models.ForeignKey(TimePeriod, on_delete=models.CASCADE)
priority = models.BooleanField(default=False)
…
class Checkin(models.Model):
client = models.ForeignKey(Client, on_delete=models.CASCADE)
choretime = models.ForeignKey(ChoreTime, on_delete=models.CASCADE)
…
Forms.py:
class CheckinForm(forms.ModelForm):
assigned_qs = 
Checkin.objects.values(‘choretime').filter(choretime_id__isnull=False)
choretime = 
forms.ModelChoiceField(queryset=ChoreTime.objects.exclude(pk__in=assigned_qs))
…
However, I cannot get the any design to work on an UpdateView form. Using the 
same form as above, the current value does not even show up – it is blank – 
because, of course, that entry is already assigned so is excluded.
What I’d like is to have the above exclusions BUT be able to also add in the 
single entry assigned to the client being updated – so the entry will show that 
specific assignment (as well as limiting any possible change options to 
unassigned values - just like on the Create).
The problems with various approaches I’ve tried are:

1. Anything done before the form is fully assembled won’t have the existing 
form’s Checkin ID value (which is part of the URL, just BTW). This is needed to 
look up and add the existing entry. So, having a database view won’t work 
without being able to communicate the existing person’s assignment ID to the 
view. Similarly, using an override queryset on the form, like done above for 
the Create, needs that ID, too.

2. If I do the queries in the class's GET method routine as ORM objects, I 
must use UNION (a union of the exclusions as above plus the existing update 
client’s assignment). That union option keeps giving an error that one of the 
ORM querysets is not a queryset. However, they are both using 
“.objects.filter…”. It seems like complex queries don’t work with the 
union command. If I use raw SQL, the query works but the assignment to the 
choretime field’s queryset fails.
Does anyone have experience with this sort of behavior and be willing to give 
guidance?

--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion o

RE: Dynamically altering a (ForeignKey) ModelChoiceField’s values

2018-04-27 Thread Matthew Pava
Well, Jim, my first message should have addressed your issue with the 
UpdateView.
Your URL keyword argument should be pk by default.  If it’s not, you have to 
set pk_url_kwarg in UpdateView.
Example:  /checkin/update/(?)

https://ccbv.co.uk/projects/Django/2.0/django.views.generic.edit/UpdateView/

class CheckinUpdate(UpdateView):
  model = Checkin
  form_class = CheckinForm


class CheckinForm(forms.ModelForm):
assigned_qs = 
Checkin.objects.values(‘choretime').filter(choretime_id__isnull=False)
choretime = 
forms.ModelChoiceField(queryset=ChoreTime.objects.exclude(pk__in=assigned_qs))

  def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# if an instance has been passed in, we need to include its value 
in the ChoreTime queryset
if hasattr(self, “instance”) and self.instance:
  self.fields[‘choretime’].queryset |= 
ChoreTime.objects.filter(pk=self.instance.choretime.pk)



From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Jim Illback
Sent: Friday, April 27, 2018 1:39 PM
To: Django users
Subject: Re: Dynamically altering a (ForeignKey) ModelChoiceField’s values

Absolutely agree. The “instance” (your note) is for Checkin and it includes a 
ForeignKey field to ChoreTime, which is a selection (choice field). But, I want 
that choice field to be limited for the forms to be only what has been not 
assigned yet. That way the user on the page will know that any shown pick is 
available. Otherwise, there are over 100 choices and no guidance as to what is 
truly available or already filled.

I have to alter the query set for that field. On a CreateView, I have it 
working perfectly (it’s shown below). However, on an UpdateView, the person’s 
choice is one of the “unavailable”. So, I’m trying to add just that one choice 
back into the query set before showing it on the form. Therefore, I need both 
the URL (to get the update’s choice) and the pre-form display method override 
(to exclude assigned entries) where I can override the field’s query set.

Thanks for the inputs, Matthew. I hope I’ve made it clearer. If you think 
there’s a better overall approach, I’m all ears!
Jim


On Apr 27, 2018, at 11:01 AM, Matthew Pava 
mailto:matthew.p...@iss.com>> wrote:

That ID in the URL should be taken care of in the view, not the form.  You pass 
the object in as keyword instance to instantiate the form.  How are you 
defining your form in the view?

Typically, you would do something like this:

instance = CheckIn.objects.get(pk=self.kwargs.get(‘pk’))
form = CheckInForm(request.POST or None, instance=instance)

From: django-users@googlegroups.com<mailto:django-users@googlegroups.com> 
[mailto:django-users@googlegroups.com] On Behalf Of Jim Illback
Sent: Friday, April 27, 2018 11:33 AM
To: Django users
Subject: Re: Dynamically altering a (ForeignKey) ModelChoiceField’s values

I also need to have the specific ID specified in the URL, so that is the other 
part needed. I’ve successfully done your suggestion for CreateView. Now, I just 
can’t seem to get UpdateView to work properly.

Thanks much!
Jim



On Apr 27, 2018, at 9:20 AM, Matthew Pava 
mailto:matthew.p...@iss.com>> wrote:

In the form’s __init__ method, you’ll have to modify the queryset of the field.

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields[‘choretime’].queryset |= 
ChoiceTime.objects.filter(pk=self.instance.pk)

I hope that helps!

From: django-users@googlegroups.com<mailto:django-users@googlegroups.com> 
[mailto:django-users@googlegroups.com] On Behalf Of Jim Illback
Sent: Friday, April 27, 2018 11:16 AM
To: Django users
Subject: Re: Dynamically altering a (ForeignKey) ModelChoiceField’s values

To make this easier, here is just a simple the question.

Does Django give a method that can be overridden while processing a form which 
has access to the incoming URL parameters and precedes the display of the 
form’s fields, specifically being able to alter the fields’s query set before 
it is displayed?

Thanks for any help to answer this question.

Jim Illback




On Apr 25, 2018, at 10:41 AM, Jim Illback 
mailto:subaru...@hotmail.com>> wrote:

I wondered if anyone has had to alter the queryset behind a model form’s 
foreign key field which presents as a model choice field?
Briefly, I have a client attribute table with the foreign key to a chore/time 
table. For an add of the client attribute table, I want to limit entries to 
unassigned chore/time combinations only. This works perfectly during my 
CreateView. Here are some extracts to show specifics:
Models.py:
class ChoreTime(models.Model):
chore = models.ForeignKey(Chore, on_delete=models.CASCADE)
time = models.ForeignKey(TimePeriod, on_delete=models.CASCADE)
priority = models.BooleanField(default=False)
…
class Checkin(models.Model):
client = models.ForeignKey(Client, 

RE: Crazy Idea: OOP for "Hyperlink"

2018-04-30 Thread Matthew Pava
Here’s Django’s documentation on widgets:
https://docs.djangoproject.com/en/2.0/ref/forms/widgets/
>From the docs:
A widget is Django’s representation of an HTML input element.

This whole idea would take some time to implement and consider ramifications.  
After all, a hyperlink isn’t really an HTML input element.

You have urlpatterns being a list of url objects.  If you could somehow take 
the attributes of the url object and copy them to a widget (through an __init__ 
method, for instance), and allow the user to customize those attributes in the 
URLWidget class.  The really tricky thing about it, though, would be handling 
permissions.

I think it is a DRY way of handling the situation.

So the data comes from your urls file, where it is also stored.  The input of 
the widget would be the url objects from the urls file.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of guettli
Sent: Monday, April 30, 2018 2:25 AM
To: Django users
Subject: Re: Crazy Idea: OOP for "Hyperlink"



Am Donnerstag, 26. April 2018 15:54:31 UTC+2 schrieb Matthew Pava:
I’ve been thinking about your idea, and I wonder if there could instead be some 
kind of widget for URL objects (or views).


A widget ... Let me think about it. A widget is a libray, is source code.
The code needs some data to operate on.
Where should the data come from? Where should I store the data?
What kind of data/input does the widget need?

I have no clue
--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/fd48e249-9d57-43f5-87e4-09bed383af62%40googlegroups.com<https://groups.google.com/d/msgid/django-users/fd48e249-9d57-43f5-87e4-09bed383af62%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

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


RE: I am following the official Django documentation and trying to make the polls app. But when I run the command python manage.py shell I get the console error.

2018-04-30 Thread Matthew Pava
You need a space between def and __str__

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Avitab Ayan Sarmah
Sent: Monday, April 30, 2018 4:07 PM
To: Django users
Subject: I am following the official Django documentation and trying to make 
the polls app. But when I run the command python manage.py shell I get the 
console error.

The code of my polls/models.py is:
import datetime

from django.db import models
from django.utils import timezone


class Question(models.Model):
#...
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
def__str__(self):
return self.question_text
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

class Choice(models.Model):
#...
def__str__(self):
return self.choice_text
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)

Please find the error in my code and help me run my code.The error is attached 
above
--
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/84560734-c5cd-4e32-9da4-7aba3202c402%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/93d21fa128fa46c5a57ec72b7cfd997b%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: OperationalError

2018-05-02 Thread Matthew Pava
“random letters & numbers”

That looks like merge conflicts with Git.  You’ll want to fix those up, not 
just by deleting those lines, but by verifying the code does what you want it 
to.
You may want to just delete all of your migrations files and start anew if 
they’re not important to you.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Gerald Brown
Sent: Wednesday, May 2, 2018 4:08 AM
To: Anthony Flury; django-users@googlegroups.com
Subject: Re: OperationalError


Thanks for the reply.

I have done the makemigrations/migrate numerous times.  Each time it says there 
is an error in the previous migration file so I have to comment out most of the 
file.  I then just deleted all of the self generated migration files and 
started fresh.

I was also getting some weird characters in my files like "random letters & 
numbers.  I deleted all of those & ran the migrations again.

The weird thing is that now when I click on the link it says "unknown column 
telephone in field list", previously it was first_name that was unknown.

I have this application running on a "similar" computer and it has NO problems 
with this area so maybe there are some other applications running that cause 
the problem even though this one is in a virtualenv.

On Wednesday, 02 May, 2018 03:00 PM, Anthony Flury wrote:
At first glance it looks like you haven't applied a migration to this computer.

at the command line on this computer  - in the man project directory :

If you have not copied the migration scripts from your development machine do 
this first :

   $ python manage.py makemigrations

and then do this :

   $ python manage.py migrate

--
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/5499b870-33e8-52db-85e2-df835be17e87%40gmail.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/21802186cf2749e6b6e191e8fc78ce26%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: OperationalError

2018-05-03 Thread Matthew Pava
I use PhantomJS with Django to create PDFs.  I just pass in the URL with the 
session variable (to maintain authentication) and a few other parameters into a 
customized Rasterize.js script.
Is it an “easy” way?  I wouldn’t say so, but it works for us.

It gets really crazy when you start asking, “Does anyone know of an easy way to 
print in Django?”  It’s not easy, but it can be done in an appropriate 
environment.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Gerald Brown
Sent: Thursday, May 3, 2018 7:22 AM
To: Django users
Subject: Re: OperationalError


FINALLY. SUCCESS!!! What I ended up doing to correct the problem was to drop 
the whole database (NO RECORDS YET). When I tried to run migrations it said 
there were no changes.  I then had to run makemigrations  and 
migrate  so I am now back in business!!!

Now does anyone know of an easy way to create PDF documents in Django???

Thanks to all for the suggestions and ideas!!!

On Thursday, May 3, 2018 at 6:13:35 PM UTC+8, Gerald Brown wrote:

I finally discovered what I think is the cause of my problem. DJANGO 
MIGRATIONS ARE NOT WORKING. On the system that has the problem is where I made 
migration to change some of the field names.  The fields that were not found 
where the ones that did get changed but the old unchanged names were still 
there.  On another system that is working NONE of the fields names were changed 
so it didn't have any unknown fields. Both systems had migrations run against 
the model file where some fields had changes made and the other one NO changes 
were made and on a third machine all changes were made.

Who knows what evil lurks in the heart of the computer? The Shadow knows!!!

On Wednesday, 02 May, 2018 07:56 AM, Gerald Brown wrote:
I have a Django application that I am having problems with.  In the Admin page 
I have 3 sections, ABC, DEF & XYZ. Each has 1 option to "Add/Change".  In 2 of 
them when I click on the option it works fine. The third gives me the following 
error "

1054, "Unknown column 'xyz_xyz.first_name' in "field list"



The Exception location is: 
/home/medrec1/.virtualenvs/medrecproj/lib/python3.5/site-packages/MySQLdb/connections.py
 in query,

line 277



On another system (both running the same code) I was also getting a different 
error also in site-packages/MySQLdb but I was

able correct that by installing 2 DEV packages and then installing MySQLClient, 
which I also did on this computer.  The other

system does NOT give this error.



Any ideas, suggestions, solutions on how to solve this error and any other 
errors in the Django code?



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/74790172-8bf5-43b6-9bad-bab68ae11a4a%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/e17d8d56-d57c-4f3d-ae6f-a004a5beda70%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/e5e175015b1d445f979cfc318cf32eec%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Query Regarding Django Signals

2018-05-04 Thread Matthew Pava
The advantage with the signals is that you can put all that code in one place.  
You may have different views that are saving the same model, and it isn’t DRY 
to have to put that same code in multiple locations.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Nipun Arora
Sent: Friday, May 4, 2018 10:37 AM
To: Django users
Subject: Query Regarding Django Signals

Hello Community

I was puzzled by the fact that if django signals are not asynchronous why do we 
use them as in when ever i want some trigger on post_save can't  i simply write 
that particular trigger in the same function that handles the request for 
saving a new object in django views..?
as in :

def handlerequest(Request):
save instance to db
   Do the work i would do in the method handling the signal post_save


--
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/5b64f4e4-afa2-485b-96a9-825b3c93b95e%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/10a41cd61e124053ae127bc226ce72fc%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Django-admin problem

2018-05-04 Thread Matthew Pava
And you’re using PowerShell instead of the command prompt.  I typically just 
work in the command prompt.  With PowerShell, you may have to be more explicit 
in your path, such as using “.\django-admin startproject mysite”

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Jani Tiainen
Sent: Friday, May 4, 2018 1:26 PM
To: django-users@googlegroups.com
Subject: Re: Django-admin problem

Hi,

By the looks of error you're running windows.

By default scripts are not in PATH so you need to type something like 
c:\python36\scripts\django-admin.py

Or you should use virtualenv (or pipenv) which would set path correctly.

pe 4. toukokuuta 2018 klo 19.51 Mikko 
mailto:mikkovillemero...@gmail.com>> kirjoitti:
Hi,

I'm trying to follow the tutorial, but I got this problem at the very beginning 
when I tried ''django-admin startproject mysite'':

django-admin : The term 'django-admin' is not recognized as the name of a 
cmdlet, function, script file, or operable pr
ogram. Check the spelling of the name, or if a path was included, verify that 
the path is correct and try again.
At line:1 char:1
+ django-admin startproject mysite
+ 
+ CategoryInfo  : ObjectNotFound: (django-admin:String) [], 
CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Could someone help me to overcome 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/28096273-fd67-4084-ba8a-f4e3c75d5916%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/CAHn91odAtLj7Xc%3DChc0f7yLZ-HY7hiM3%3DaNSRxhY1MQd_qbREw%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/9a713a6d5e6a43e987a422e33be385e1%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: can you check what is wrong with def vote(request, question_id), i am not able to run server. The exceptions and my views.py code are wrriten below:

2018-05-08 Thread Matthew Pava
Hi Avitab,
The exception message tries to explain it to you.
“IndentationError: unindent does not match any outer indentation level”
Python expects perfect whitespace with your code, and you can’t mix spaces with 
tabs.
In your view function, you are indenting with 4 spaces most of the time, but 
your first line in the function is with a tab.
I recommend using an IDE such as PyCharm to help alleviate this issue so you 
don’t run into it again.



From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Avitab Ayan Sarmah
Sent: Tuesday, May 8, 2018 10:54 AM
To: Django users
Subject: can you check what is wrong with def vote(request, question_id), i am 
not able to run server. The exceptions and my views.py code are wrriten below:

Views.py:

from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views import generic

from . models import Choice, Question


class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'

def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.order_by('-pub_date')[:5]


class DetailView(generic.DetailView):
model = Question
template_name = 'polls/detail.html'


class ResultsView(generic.DetailView):
model = Question
template_name = 'polls/results.html'


def vote(request, question_id):
... # Same as above, no changes needed.
question = get_object_or_404(Question, pk=question_id)
try:
selected_choice = question.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
# Redisplay the question voting form.
return render(request, 'polls/detail.html', {
'question': question,
'error_message': "You didn't select a choice.",
})
else:
selected_choice.votes += 1
selected_choice.save()
# Always return an HttpResponseRedirect after successfully dealing
# with POST data. This prevents data from being posted twice if a
# user hits the Back button.
return HttpResponseRedirect(reverse('polls:results', 
args=(question.id,)))



Exceptions:

Unhandled exception in thread started by .wrapper at 0x0261B72329D8>
Traceback (most recent call last):
  File "c:\python36\lib\site-packages\django\utils\autoreload.py", line 225, in 
wrapper
fn(*args, **kwargs)
  File 
"c:\python36\lib\site-packages\django\core\management\commands\runserver.py", 
line 121, in inner_run
self.check(display_num_errors=True)
  File "c:\python36\lib\site-packages\django\core\management\base.py", line 
364, in check
include_deployment_checks=include_deployment_checks,
  File "c:\python36\lib\site-packages\django\core\management\base.py", line 
351, in _run_checks
return checks.run_checks(**kwargs)
  File "c:\python36\lib\site-packages\django\core\checks\registry.py", line 73, 
in run_checks
new_errors = check(app_configs=app_configs)
  File "c:\python36\lib\site-packages\django\core\checks\urls.py", line 40, in 
check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
  File "c:\python36\lib\site-packages\django\core\checks\urls.py", line 57, in 
_load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
  File "c:\python36\lib\site-packages\django\utils\functional.py", line 36, in 
__get__
res = instance.__dict__[self.name] = self.func(instance)
  File "c:\python36\lib\site-packages\django\urls\resolvers.py", line 536, in 
url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "c:\python36\lib\site-packages\django\utils\functional.py", line 36, in 
__get__
res = instance.__dict__[self.name] = self.func(instance)
  File "c:\python36\lib\site-packages\django\urls\resolvers.py", line 529, in 
urlconf_module
return import_module(self.urlconf_name)
  File "c:\python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 978, in _gcd_import
  File "", line 961, in _find_and_load
  File "", line 950, in _find_and_load_unlocked
  File "", line 655, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 205, in _call_with_frames_removed
  File "C:\Users\AVITABAYAN\mysite\mysite\urls.py", line 5, in 
path('', include('polls.urls')),
  File "c:\python36\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
  File "c:\python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 978, in _gcd_import
  File "", line 961, in _find_and_load
  File "", line 950, in _find_and_load_unlock

Case inconsistency

2018-05-09 Thread Matthew Pava
I came across an interesting issue recently.  I had a form with an action set 
to "GET".  The corresponding view was a django-rest-framework view that was 
just supposed to allow for GET requests.  However, I couldn't get it to work 
because drf was expecting lower case names, and it turns out that HTML5 expects 
a lowercase action set to "get".

Yet the request variables are capitalized.
request.GET
request.POST

I suppose that we're saying that those variables are "constants" and should 
follow the naming convention of capitalizing them.  They are immutable 
dictionaries after all.  So I guess I've answered my own question.

-- 
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/1f2c597bd7ec4dedabdb31b11062d7c2%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Case inconsistency

2018-05-10 Thread Matthew Pava
My comment was stated inaccurately.  The method attribute was set to "GET" on 
the form element.  It only worked when I set it to "get".
I learned XHTML (strict), which requires elements and attributes to be 
lowercase (which, for some reason, I violated when I set the attribute to 
"GET").  I forgot that that requirement was lifted with HTML5.

Your reference is interesting because it seems to imply that the method 
attribute has to be uppercase.  Maybe the browser translates it to uppercase 
before sending it to the server?  But then that doesn't explain why I got two 
different results based on the case of the method attribute.

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Melvyn Sopacua
Sent: Wednesday, May 9, 2018 6:21 PM
To: django-users@googlegroups.com
Subject: Re: Case inconsistency

On woensdag 9 mei 2018 23:00:06 CEST Matthew Pava wrote:
> I came across an interesting issue recently.  I had a form with an 
> action set to "GET".  The corresponding view was a 
> django-rest-framework view that was just supposed to allow for GET 
> requests.  However, I couldn't get it to work because drf was 
> expecting lower case names, and it turns out that
> HTML5 expects a lowercase action set to "get".

HTML is not your reference (and case insensitive to boot). HTML does not make 
requests, it just specifies how responses are rendered. HTTP makes requests:
https://tools.ietf.org/html/rfc2616#page-36
--
Melvyn Sopacua

--
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/5432858.BvN9p53GFH%40fritzbook.
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/71535c90594c49719fe1f70376d7e7a0%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Deploy on windows IIS

2018-05-11 Thread Matthew Pava
I know it doesn’t directly answer your question, but I have Django running on 
Windows Server 2012.  After wrestling with IIS for just a bit, I decided to 
just use Apache instead.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Majid Hojati
Sent: Friday, May 11, 2018 12:52 PM
To: Django users
Subject: Deploy on windows IIS

Hi,
I have faced a problem while deploying django on windows server 2008 with IIS
I followed this
http://blog.mattwoodward.com/2016/07/running-django-application-on-windows.html

and it returns unexpectedly exited error. I am using python 3.6 and the 
development pythons server runs with no problem but I can not configure factcgi,
What options do I have? I can not even find the problem with this error.
--
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/81d75081-c368-498d-9980-3b0e0d0feefe%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/4c33a4b74dbf4eb68b663bdfac96cb0e%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Deploy on windows IIS

2018-05-11 Thread Matthew Pava
I just go straight to the source or Google around.
https://httpd.apache.org/docs/2.4/platform/windows.html
Apache has different flavors for Windows.  We’re either using ApacheHaus or 
Apache Lounge.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Majid Hojati
Sent: Friday, May 11, 2018 1:33 PM
To: Django users
Subject: Re: Deploy on windows IIS

Is there any good tuturial which I can use Apache? I am also using Geoserver 
which runs on tomcat port 8080 I hope it does not make any problems

On Friday, May 11, 2018 at 10:55:45 PM UTC+4:30, Matthew Pava wrote:
I know it doesn’t directly answer your question, but I have Django running on 
Windows Server 2012.  After wrestling with IIS for just a bit, I decided to 
just use Apache instead.

From: django...@googlegroups.com 
[mailto:django...@googlegroups.com] On Behalf Of Majid Hojati
Sent: Friday, May 11, 2018 12:52 PM
To: Django users
Subject: Deploy on windows IIS

Hi,
I have faced a problem while deploying django on windows server 2008 with IIS
I followed this
http://blog.mattwoodward.com/2016/07/running-django-application-on-windows.html

and it returns unexpectedly exited error. I am using python 3.6 and the 
development pythons server runs with no problem but I can not configure factcgi,
What options do I have? I can not even find the problem with this error.
--
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 djang...@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/81d75081-c368-498d-9980-3b0e0d0feefe%40googlegroups.com<https://groups.google.com/d/msgid/django-users/81d75081-c368-498d-9980-3b0e0d0feefe%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/52e5c404-69ff-45a1-910d-aeda09ad58f0%40googlegroups.com<https://groups.google.com/d/msgid/django-users/52e5c404-69ff-45a1-910d-aeda09ad58f0%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

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


RE: Deploy on windows IIS

2018-05-14 Thread Matthew Pava
Yes, getting the right combination of mod_wsgi in Windows can be tricky.
This URL is most helpful with that:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
Be sure to get the Apache with the correct Visual C runtime and the right 
number of bits.

No, I don’t uninstall IIS because I’m using it for other server services.  I 
have one IP address dedicated to the Apache server, and another for IIS.
I don’t use Geoserver or TomCat, so I don’t know much about their 
configuration.  I’m sure that you can get them to work alongside Apache, though.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Majid Hojati
Sent: Saturday, May 12, 2018 12:24 PM
To: Django users
Subject: Re: Deploy on windows IIS

Which Mode_wsgi you used for python 3.6 x86 and apache2.4 Haus x64 for windows ?

On Friday, May 11, 2018 at 11:07:19 PM UTC+4:30, Matthew Pava wrote:
I just go straight to the source or Google around.
https://httpd.apache.org/docs/2.4/platform/windows.html
Apache has different flavors for Windows.  We’re either using ApacheHaus or 
Apache Lounge.

From: django...@googlegroups.com 
[mailto:django...@googlegroups.com] On Behalf Of Majid Hojati
Sent: Friday, May 11, 2018 1:33 PM
To: Django users
Subject: Re: Deploy on windows IIS

Is there any good tuturial which I can use Apache? I am also using Geoserver 
which runs on tomcat port 8080 I hope it does not make any problems

On Friday, May 11, 2018 at 10:55:45 PM UTC+4:30, Matthew Pava wrote:
I know it doesn’t directly answer your question, but I have Django running on 
Windows Server 2012.  After wrestling with IIS for just a bit, I decided to 
just use Apache instead.

From: django...@googlegroups.com<mailto:django...@googlegroups.com> 
[mailto:django...@googlegroups.com] On Behalf Of Majid Hojati
Sent: Friday, May 11, 2018 12:52 PM
To: Django users
Subject: Deploy on windows IIS

Hi,
I have faced a problem while deploying django on windows server 2008 with IIS
I followed this
http://blog.mattwoodward.com/2016/07/running-django-application-on-windows.html

and it returns unexpectedly exited error. I am using python 3.6 and the 
development pythons server runs with no problem but I can not configure factcgi,
What options do I have? I can not even find the problem with this error.
--
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<mailto:django-users...@googlegroups.com>.
To post to this group, send email to 
djang...@googlegroups.com<mailto:djang...@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/81d75081-c368-498d-9980-3b0e0d0feefe%40googlegroups.com<https://groups.google.com/d/msgid/django-users/81d75081-c368-498d-9980-3b0e0d0feefe%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users...@googlegroups.com.
To post to this group, send email to djang...@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/52e5c404-69ff-45a1-910d-aeda09ad58f0%40googlegroups.com<https://groups.google.com/d/msgid/django-users/52e5c404-69ff-45a1-910d-aeda09ad58f0%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/da02dd76-72a7-4c41-9c9e-c9cf9a743345%40googlegroups.com<https://groups.google.com/d/msgid/django-users/da02dd76-72a7-4c41-9c9e-c9cf9a743345%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

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

RE: SQL select statements to Django ORM

2018-05-14 Thread Matthew Pava
You could use the ORM to get the difference of two dates like so:
Person.objects.annotate(age=ExpressionWrapper(Cast(Now(), DateField()) - 
F('dob'), output_field=DurationField()))
https://docs.djangoproject.com/en/2.0/ref/models/database-functions/#cast
https://docs.djangoproject.com/en/2.0/ref/models/database-functions/#now


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Melvyn Sopacua
Sent: Monday, May 14, 2018 5:56 AM
To: django-users@googlegroups.com
Subject: Re: SQL select statements to Django ORM

On zondag 13 mei 2018 03:44:37 CEST Gerald Brown wrote:
> As I have said previously, I am new to Django ORM so I would like to 
> know howto/find reference to Django ORM Query to the following SQL 
> Select
> statements:

Do you want to use SQL or use Django? Pick one.

> 1. From Mariadb.
> 
> SELECT name, date_of_birth,
> *TIMESTAMPDIFF(YEAR,date_of_birth,'2014-08-02'/or curdate())* AS age 
> FROM some table.

The Django way:

Use case: I want to gather a person's name, date of birth and age for all 
people modeled using Person.

from datetime import date

class Person(models.Model):
name = models.CharField(max_length=100)
dob = models.DateField()

@property
def age(self) -> int:
diff = date.today() - self.dob
return diff.year

people = Person.objects.defer('name', 'dob').all()

> 2. General SQL statement
> SELECT field1, field2, field10 from some table

See defer() as above.

> 3. How to see all of the data from those statements which SQL shows me.

Use case: I want to show people's name, date of birth and age.

Using above "people":

print('name', 'date of birth', 'age')
for person in people:
print(people.name, people.dob, people.age)

--
Melvyn Sopacua

--
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/4418595.HAJx60YL8B%40fritzbook.
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/8f9fca34d3464ace8a0720cd374b15b7%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: SQL select statements to Django ORM

2018-05-14 Thread Matthew Pava
Maybe it's just me, but I had a report I was generating that took 3.5 minutes 
to complete that utilized for loops and the ORM.  I managed to generate the 
same report in 18 seconds using a RawSQL query.
So what's the upside?  Speed.  I would understand if the times were comparable, 
but they're not.
I find myself becoming more and more blocked by the limited functionality of 
the ORM in this regard.  Perhaps it's just my application--maybe Django isn't 
the best fit for it.

But if in your use case, you had a million records in which you were trying to 
filter by age using Python loops, I have a suspicion that it would be slower 
than using the database functions that Django does include.  (Saying that, I 
would like to see the Django community make a greater attempt to making those 
functions more pythonic.)

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Melvyn Sopacua
Sent: Monday, May 14, 2018 9:29 AM
To: django-users@googlegroups.com
Subject: Re: SQL select statements to Django ORM

On maandag 14 mei 2018 15:38:01 CEST Matthew Pava wrote:
> You could use the ORM to get the difference of two dates like so:
> Person.objects.annotate(age=ExpressionWrapper(Cast(Now(), DateField()) 
> - F('dob'), output_field=DurationField())) 
> https://docs.djangoproject.com/en/2.0/ref/models/database-functions/#c
> ast 
> https://docs.djangoproject.com/en/2.0/ref/models/database-functions/#n
> ow

Sure, but what's the upside? The downside is that your objects are bigger, more 
data transferred from db to python layer, more complex query.

What I'm trying to conveigh here, is not to shoehorn the ORM into your notion 
of SQL, but to think in models, model fields, object properties and model 
relations.

There will be times where the ORM needs help from SQL, but pick your battles.
--
Melvyn Sopacua

--
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/4047248.Nn77cOrblS%40fritzbook.
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/a1fcdf93225e48f4a23ea42fff240cac%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: SQL select statements to Django ORM

2018-05-14 Thread Matthew Pava
It was a conditional statement, albeit a seemingly poorly constructed one.

"If you had a million records you were trying to filter..."

Would you not just replace "annotate" with "filter" and use the same 
DurationField() expression?

Nevertheless, in my case, I would use the annotation for a report that shows 
counts based on certain criteria.

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Melvyn Sopacua
Sent: Monday, May 14, 2018 4:32 PM
To: django-users@googlegroups.com
Subject: Re: SQL select statements to Django ORM

On maandag 14 mei 2018 16:42:49 CEST Matthew Pava wrote:

> But if in your use case, you had a million records in which you were 
> trying to filter

Full stop right there. No one is filtering anything in the original use case, 
so you're comparing apples and oranges.
Filtering you would do in the database, but you'd still not use annotate, cause 
you can simply filter on the dob using standard __gte/__lte etc. lookups.
--
Melvyn Sopacua

--
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/1618227.LY2WuIfJ59%40fritzbook.
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/0d81237ad6374038b583366bf3394dfb%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: django 2.0 tutorial :: exception:: application labels are not unique.

2018-05-15 Thread Matthew Pava
Though I’ve never seen that error, I’m guessing that maybe you added ‘polls’ to 
your INSTALLED_APPS setting more than once.  Simply remove the extra references 
to it.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Paolo Chilosi
Sent: Tuesday, May 15, 2018 6:52 AM
To: Django users
Subject: django 2.0 tutorial :: exception:: application labels are not unique.

As new to Django I am learning following the tutorial carefully. When I reached 
the point of making the migration for the polls app I executed (from the 
PyCharm terminal) the command:

(venv) C:\Users\Paolo\PycharmProjects\mysite>python manage.py makemigration 
polls

and then I obtained the following exception messages

Traceback (most recent call last):
  File "manage.py", line 15, in 
execute_from_command_line(sys.argv)
  File 
"C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\core\management\__ini
t__.py", line 371, in execute_from_command_line
utility.execute()
  File 
"C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\core\management\__ini
t__.py", line 347, in execute
django.setup()
  File 
"C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\__init__.py",
 line 24
, in setup
apps.populate(settings.INSTALLED_APPS)
  File 
"C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\apps\registry.py",
 line 93, in populate
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, 
duplicates: polls
(venv) C:\Users\Paolo\PycharmProjects\mysite>

I reviewed carefully the code and restarted the tutorial several times , all 
the times having the same problem.

ANY SUGGESTION?? 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/653a7dd7-b330-4062-86b2-3fa06598008a%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/1e6238fce8ad4f4fbb9706fda6390236%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: def get_queryset(self): ^ IndentationError: unindent does not match any outer indentation level

2018-05-18 Thread Matthew Pava
Avitab,
Whitespace is very important to Python.
You added an extra tab to your else and else clause of your try expression.
Consider the error message: unindent does not match outer indentation level
The message is mentioning indents, so let’s check our indents for any problems.


try:
selected_choice = 
question.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
#Redisplay the question voting form.
return render(request, 'polls/detail.html', 
{
'question': question,
'error_message': "you didn't 
select a choice.",
})
else:
selected_choice.votes +=1
selected_choice.save()
#...
#...
#...
return 
HttpResponseRedirect(reverse('polls:results', args=(question.id,)))


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Avitab Ayan Sarmah
Sent: Friday, May 18, 2018 11:09 AM
To: Django users
Subject: def get_queryset(self): ^ IndentationError: unindent does not match 
any outer indentation level

While going through the django project i committed an error while executing 
"python manage.py runserver" inside my project directory.It is showing error is 
in line 24 of views.py.Please comment what exact the error is and how do i 
overcome this error.The exceptions and views.py is mentioned below:

Exceptions:

PS C:\Users\AVITABAYAN\mysite> python manage.py runserver
Performing system checks...

Unhandled exception in thread started by .wrapper at 0x017BA5FB29D8>
Traceback (most recent call last):
  File "c:\python36\lib\site-packages\django\utils\autoreload.py", line 225, in 
wrapper
fn(*args, **kwargs)
  File 
"c:\python36\lib\site-packages\django\core\management\commands\runserver.py", 
line 121, in inner_run
self.check(display_num_errors=True)
  File "c:\python36\lib\site-packages\django\core\management\base.py", line 
364, in check
include_deployment_checks=include_deployment_checks,
  File "c:\python36\lib\site-packages\django\core\management\base.py", line 
351, in _run_checks
return checks.run_checks(**kwargs)
  File "c:\python36\lib\site-packages\django\core\checks\registry.py", line 73, 
in run_checks
new_errors = check(app_configs=app_configs)
  File "c:\python36\lib\site-packages\django\core\checks\urls.py", line 40, in 
check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
  File "c:\python36\lib\site-packages\django\core\checks\urls.py", line 57, in 
_load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
  File "c:\python36\lib\site-packages\django\utils\functional.py", line 36, in 
__get__
res = instance.__dict__[self.name] = self.func(instance)
  File "c:\python36\lib\site-packages\django\urls\resolvers.py", line 536, in 
url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "c:\python36\lib\site-packages\django\utils\functional.py", line 36, in 
__get__
res = instance.__dict__[self.name] = self.func(instance)
  File "c:\python36\lib\site-packages\django\urls\resolvers.py", line 529, in 
urlconf_module
return import_module(self.urlconf_name)
  File "c:\python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 978, in _gcd_import
  File "", line 961, in _find_and_load
  File "", line 950, in _find_and_load_unlocked
  File "", line 655, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 205, in _call_with_frames_removed
  File "C:\Users\AVITABAYAN\mysite\mysite\urls.py", line 5, in 
path('', include('polls.urls')),
  File "c:\python36\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
  File "c:\python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 978, in _gcd_import
  File "", line 961, in _find_and_load
  File "", line 950, in _find_and_load_unlocked
  File "", line 655, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 205, in _call_with_frames_removed
  File "C:\Users\AVITABAYAN\mysite\polls\urls.py", line 3, in 
from . import views
  File "C:\Users\AVITABAYAN\mysite\polls\views.py", line 24
def get_queryset(self):
  ^
IndentationError: unindent does not match any outer indentation level


views.py:

from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRe

f-strings with self.stdout management commands

2018-05-21 Thread Matthew Pava
I was using Python 3's f-strings with self.stdout in a BaseCommand.
I keep getting this exception:
TypeError: 'OutputWrapper' object is not callable

Any ideas?

-- 
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/ab17b313e3e44e01b7c9a3a55fddc7a5%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: f-strings with self.stdout management commands

2018-05-21 Thread Matthew Pava
Nevermind…
I was using self.stdout(f’’)
Instead of
self.stdout.write(f’’)

Go figure…

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Matthew Pava
Sent: Monday, May 21, 2018 9:21 AM
To: django-users@googlegroups.com
Subject: f-strings with self.stdout management commands

I was using Python 3’s f-strings with self.stdout in a BaseCommand.
I keep getting this exception:
TypeError: ‘OutputWrapper’ object is not callable

Any ideas?

--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/ab17b313e3e44e01b7c9a3a55fddc7a5%40ISS1.ISS.LOCAL<https://groups.google.com/d/msgid/django-users/ab17b313e3e44e01b7c9a3a55fddc7a5%40ISS1.ISS.LOCAL?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

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


RE: How to get the primary key of the underlying model in a ModelForm?

2018-05-29 Thread Matthew Pava
You can access self.instance, which should have all the fields populated for 
that model instance.  So you can access it via self.instance.pk.

Keep in mind, though, that if you are creating the Document, you will not have 
a pk until after the save is committed, so it won’t be accessible in the clean 
method.  If you are updating a document, then pk will populated.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Mark Phillips
Sent: Tuesday, May 29, 2018 4:15 PM
To: django users
Subject: How to get the primary key of the underlying model in a ModelForm?

I have a model, Document, and an associated DocumentForm(forms. ModelForm), and 
a DocumentAdmin(admin.ModelAdmin). In the clean method of the DocumentForm, I 
need to get the document_id (ie primary key) of the underlying Document, but it 
is not included in the field set for that form. I need the primary key, because 
one of the fields on the form belongs to another model (it is a JSON field), 
and I need to save that field in the other model when the DocumentForm is saved.

How do I access the primary key of the underlying Model in a ModelForm?

Thanks!

Mark
--
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/CAEqej2OAvc78CgykeYYs5Wvc-MPQRR0Lnhp5NYQt3hpVf_cv8w%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/1a98417972974d919030e6a5ed76cced%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Inlineformset without foreign key possible?

2018-06-05 Thread Matthew Pava
I’m not able to wrap my head around your specific application, but if you don’t 
want to use a ForeignKey on a formset, don’t use an InlineFormset.
Just use a regular BaseFormset.
https://docs.djangoproject.com/en/2.0/topics/forms/formsets/


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Layne Sadler
Sent: Tuesday, June 5, 2018 4:04 PM
To: Django users
Subject: Inlineformset without foreign key possible?


I'm trying to implement an inline formset for two models in a graph database. 
The problem that I'm running into is that formsets are designed with foreign 
keys in mind.



I'm relating a model to itself through another model. For simplicity sake, 
let's call them a Person model and a FriendRel model:

Person -[FRIENDS_WITH]-> Person

FriendRelFormSet = inlineformset_factory(Person, FriendRel, form=FriendRelForm, 
extra=1)



I've tried setting the fk_name=None argument, but I am still met with the 
following error:



ValueError: 'django_rel.RelationshipMeta' has no ForeignKey to 
'django_node.NodeMeta'.



So now I am looking into the documentation below, but it is a bit abstract for 
my skillset. Am I banging my head against the wall with this, or is it possible 
to avoid the whole foreign key thing?

Overriding methods on an InlineFormSet   
https://docs.djangoproject.com/en/2.0/topics/forms/modelforms/#overriding-methods-on-an-inlineformset
--
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/dcbe2177-6593-4b6d-b0a6-6a9af3813f19%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/c0bc1272ab194885839c717a29977411%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


BaseInlineFormSet with unique_together Model

2016-10-31 Thread Matthew Pava
Good day,
I am new to this list, but I would like to understand better what is going on 
and how I can fix it the Django way.

I have a model similar to the ingredients list of a recipe.
class FoodItem(models.Model):
name = models.CharField()

class Recipe(models.Model):
input = models.ForeignKey(FoodItem, related_name="recipe", ...)
qty = models.FloatField()
ingredient = models.ForeignKey(FoodItem, ...)

class Meta:
unique_together = ('input', 'ingredient')

We don't want the recipe to list the same ingredient twice.
Then I make a basic BaseInlineFormSet.  I use Javascript to add forms and 
delete forms dynamically.  So let's say I first create this data:
Input, Qty, Ingredient
Cookies, 1, Sugar
Cookies, 2, Eggs
Cookies, 4, Flour
Cookies, 1, Chocolate Chips

It's perfect.  Then I go back and try to update the data.  I remove the Flour 
from the recipe.  It gets marked for deletion and hidden from the user.  Then I 
think, "Oh wait!  That was supposed to be 6 of the Flour!"  So I add a new data 
entry form to the formset with this data:
Cookies, 6, Flour

I click on save, and I get a validation error.  That input and ingredient 
already exist.  And it's right.  The form marked for deletion that has 4 Flour 
does not get deleted until the call to formset.save().  But the new form is not 
valid because it violates the unique constraint on the model.  I did develop a 
roundabout way of dealing with the situation: I simply delete all the instances 
from the database for forms that are marked for deletion before calling 
formset.is_valid().  But I keep thinking to myself that there must be something 
I am missing.

Thank you,
Matthew Pava



-- 
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/84f80d96f27b4370bb667740a9b75651%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: How to fetch data from LDAP to html textbox

2016-11-03 Thread Matthew Pava
We use a package called django-auth-ldap.
https://pythonhosted.org/django-auth-ldap/

It saves some of the LDAP data into the User model everytime the user logs in.  
We also have our own Employee model that has a foreign key to the User model, 
and if the user logs in without an employee record they are not allowed to 
proceed.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Owen Cai
Sent: Wednesday, November 2, 2016 9:08 AM
To: Django users
Subject: How to fetch data from LDAP to html textbox

I am pretty new to Python and Django. Recently my team ask me to develop a web 
app based on Django 1.9 for the company. The authentication part involved using 
LDAP but not a common way I can search in google.
On the top of the interface will have 2 button "use for self" and "use for 
others"
Under these 2 buttons, will have couple rows of import text boxes for employee 
information such as id, name, email address etc.
If the user choose "use for self", all the employee info need be 
automatically filled up through data from LDAP.
If the user choose "use for others", then the user need input the employee 
id, if the id is valid, all the rest information will filled up.

I will be appreciate if anyone can give me some advises such as:
   What is the easiest way to approach these functions under 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/2301c5da-5d24-48d7-bf7e-1fd949deaa76%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/b046131b24764b73b556577e2ec32dd5%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: ListField, JSONField and DictField

2016-11-03 Thread Matthew Pava
I do see them available as Postgres fields because Postgres supports them 
natively.  I assume that they aren’t by default in model Fields because other 
databases may not support them natively.

https://docs.djangoproject.com/en/1.10/ref/contrib/postgres/fields/


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Lekan Wahab
Sent: Thursday, November 3, 2016 2:21 PM
To: django-users@googlegroups.com
Subject: ListField, JSONField and DictField


Hi guys,
This question just came to me this evening and I've really been thinking about 
it.

Can someone explain to me why Django doesn't have ListField, JSONField or 
DictField by default in its model Fields?

I mean,  these are obviously things that would ease a lot of work so why aren't 
they available yet?

Lekan.
Python is the "most powerful language you can still read".
--
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/CAE6v7od4Au4friMr-bqp02JeL_R4jXVBJn3zFh6bc-eds-GtWQ%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/246d716d47584f4b90887436f40b0615%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Class Based Views VS DRY principle

2016-11-04 Thread Matthew Pava
Just create another CBV that factors out all of the similarities between all of 
the other CBVs.  Then inherit from your new CBV to create your more specific 
ones.  Basically instead of inheriting from the Django CBVs, you will inherit 
from your own.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Artem Bernatskyy
Sent: Friday, November 4, 2016 10:56 AM
To: Django users
Subject: Class Based Views VS DRY principle

Hello.

Suppose i have a code (http://pastebin.com/6rUqKD8q)

And in CBV there are a bunch of methods with EXACTLY the same code.

My question is - can i somehow inherit them from ONE place, in order to be able 
to edit them from one place ?

Thanks for replies.
--
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/51ca427d-732a-4223-bf27-59fa7b346295%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/9498a12178a74e8a985b8d744d6e3403%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Django ponycheckup check up results

2016-11-04 Thread Matthew Pava
I am just a regular user, but I don’t see how a Django setting could possibly 
modify some such a setting on the web server.  I would just learn how to write 
that EB command and take it from there.  …I suppose you could try writing a 
Python function or a Django command that will append your desired setting to 
the .htaccess file when you run it.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Sandeep Patil
Sent: Friday, November 4, 2016 12:27 PM
To: Django users
Subject: Re: Django ponycheckup check up results

Dear all,

Noone else here who has this issue? Really would like to learn how this works.

Thanks,
Sandeep

On Saturday, September 17, 2016 at 9:29:29 PM UTC+2, Sandeep Patil wrote:
Dear All,

I checked my django site a security ponycheckup at 
ponycheckup.com and I got 90%, which is good. However I 
am stuck at resolving the error "
Web server allows TRACE
Your web server allows the TRACE method. This is not good, as it rarely serves 
a purpose, and can be used in cross-site scripting attacks."

I tried to look around for answers and most of them had solutions for modifying 
htaccess file. Since I use AWS EB, I dont want to manually modify any server 
files (because they get overwritten and writing a EB command looks very hacky). 
Is there a Django way of resolving this issue (some setting in settings.py)?




--
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/1c3425eb-1e44-4297-8d3b-7925b5c24313%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/398c2ea5261b41e6a4f8fd10da750ab1%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: One template for multiple views

2016-11-07 Thread Matthew Pava
I would use an if block in the template, and actually, I do use an if block.
So I would have either two context variables with this_month and last_month or 
I would look up some filter or template tag to find the month of the current 
datetime object in the Django documentation.


{% if month = this_month %}Current{% elif month = last_month %}Previous{% else 
%}{{ month }}{% endif %} Report



From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Moreplavec
Sent: Monday, November 7, 2016 1:25 PM
To: Django users
Subject: Re: One template for multiple views

Yes, i know i can pass data (variables) from view to template. But my question 
is, if i have report, for example with headline "This month" and same report 
for previous with headline "Previous month", if i can such things solve 
directly in template, based on view which is calling template. I don't like the 
way to put texts into template just to be specific for view.

But thanks for answer, it's django-way and i have to respect it :/

Dne středa 2. listopadu 2016 20:28:22 UTC+1 Lekan Wahab napsal(a):

Hi,
I'm not sure I completely understand what you need but if I do,  I think 
passing different contexts to the same template would help you achieve that.

You could easily have something like :

def initial_view(request) :
   variableone = 'a'
   variabletwo = 'b'
   return response(yourtemplate, {'a':variableone, 'b' :variabletwo})

Then you can also have another view using the same template but with different 
contexts.
Something like,

def final_view(request) :
   variableone = 'c'
   variabletwo = 'd'
   return response(yourtemplate, {'c':variableone, 'd' :variabletwo})

Also,  if you have a repetitive section in your template, you could just write 
it once and use the {% include %} tag to use it in each of your other templates.

I hope that helps.

Lekan.
Python is the "most powerful language you can still read".

On 2 Nov 2016 19:48, "Moreplavec" > wrote:
Greetings,

i'm creating template for simple table report. Data shown are for current 
month. Than i realised i need same report for previous month. I can copy 
created template and modify texts, but i don't like. Is it possible to use same 
template for more views and only controll differences based on view, which is 
template calling? For example, i need to show "Current month" or "Previous 
month". I can put these texts into variable, but i hope there is better way to 
controll directly in template.

Please, can you help me or point me to some good article? 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...@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/a61a7a9d-06a2-4749-bf71-f6d2351396af%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/08ec103b-8f35-414e-9c94-a3ee5e398cc5%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/d2c3952ed4b0489c920f5dac64f078c2%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: strategies for adding a custom group permission

2016-11-08 Thread Matthew Pava
Hi Larry,

I would just write my own custom view using my own custom forms to do this.  I 
would add my own custom permissions to apply to my custom view.  I would avoid 
using DjangoAdmin to handle such a customized use case.


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Larry Martell
Sent: Tuesday, November 8, 2016 8:56 AM
To: django-users@googlegroups.com
Subject: strategies for adding a custom group permission

I posed a question yesterday asking how to separate the group editing 
permissions from the permission to edit a new custom group permission that I 
added. I did not get any replies to that and in researching it I am thinking 
perhaps that is not possible. So I want to pose the question differently - here 
is my use case:

I need to add a configurable data filter that will be used in my app and I want 
that filter to be specifiable at the django group level. I want to be able to 
give users permission, both at the group level and the user level, to edit this 
filter. But I want that permission to be separate and distinct from the general 
change group permission.

Anyone have a method to do 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/CACwCsY5obPixfPnFtZxR3z46d5nbdqvFV5%2B-uz9K9XF-RxHLww%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/793143e6ec724691bb6aff255cac7275%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Admin Email From Address

2016-11-14 Thread Matthew Pava
I would like to be able to change the 'from' address of the admin error emails 
in production environments to be the email address of the user that generated 
the error.  It would be convenient in triaging errors rather quickly.

I did examine the Django source code, but it doesn't appear to be possible 
without writing my own custom function.  Any ideas?

Thank you!

-- 
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/29de56e899934c489630983151e28092%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Admin Email From Address

2016-11-15 Thread Matthew Pava
In such cases, we would have a fallback that is already established in the 
settings file.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Constantine Covtushenko
Sent: Tuesday, November 15, 2016 12:46 AM
To: django-users@googlegroups.com
Subject: Re: Admin Email From Address


Hi Matthew,

There should be considered following:
1. Not always cod runs with user interaction - worker cases
2. Not always user authenticated

With such cases who the sender should be?

Regards,
Constantine C.

On Nov 15, 2016 12:43 AM, "Matthew Pava" 
mailto:matthew.p...@iss.com>> wrote:
I would like to be able to change the ‘from’ address of the admin error emails 
in production environments to be the email address of the user that generated 
the error.  It would be convenient in triaging errors rather quickly.

I did examine the Django source code, but it doesn’t appear to be possible 
without writing my own custom function.  Any ideas?

Thank you!

--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/29de56e899934c489630983151e28092%40ISS1.ISS.LOCAL<https://groups.google.com/d/msgid/django-users/29de56e899934c489630983151e28092%40ISS1.ISS.LOCAL?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/CAK52boX3QBmimdd3z5YSbKDOAMOeDrX6iF3NzvsLs-fNx2PO1g%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CAK52boX3QBmimdd3z5YSbKDOAMOeDrX6iF3NzvsLs-fNx2PO1g%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

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


RE: Admin Email From Address

2016-11-15 Thread Matthew Pava
The error emails only go to the admins: me.  I would not be confused because 
the subject line of the email indicates that it is coming from the Django app 
starting with [Django].  The value in receiving the emails with the user’s 
email address is so that if, for instance, the president of the company gets an 
error page or anyone else gets an error page, I can very quickly determine 
which error I should focus on by simply glancing on who the email is from.  (In 
this case, the president…)

From: kostyak7...@gmail.com [mailto:kostyak7...@gmail.com] On Behalf Of 
Constantine Covtushenko
Sent: Tuesday, November 15, 2016 2:27 PM
To: django-users@googlegroups.com
Subject: Re: Admin Email From Address

Sorry but I do not see any valuable reason of doing things in such way.

Email is sent from wrong sender.
And if someone decides to email back than those user would be confused.

It is better to call things by its name.

On Tue, Nov 15, 2016 at 4:05 PM, Matthew Pava 
mailto:matthew.p...@iss.com>> wrote:
In such cases, we would have a fallback that is already established in the 
settings file.

From: django-users@googlegroups.com<mailto:django-users@googlegroups.com> 
[mailto:django-users@googlegroups.com<mailto:django-users@googlegroups.com>] On 
Behalf Of Constantine Covtushenko
Sent: Tuesday, November 15, 2016 12:46 AM
To: django-users@googlegroups.com<mailto:django-users@googlegroups.com>
Subject: Re: Admin Email From Address


Hi Matthew,

There should be considered following:
1. Not always cod runs with user interaction - worker cases
2. Not always user authenticated

With such cases who the sender should be?

Regards,
Constantine C.

On Nov 15, 2016 12:43 AM, "Matthew Pava" 
mailto:matthew.p...@iss.com>> wrote:
I would like to be able to change the ‘from’ address of the admin error emails 
in production environments to be the email address of the user that generated 
the error.  It would be convenient in triaging errors rather quickly.

I did examine the Django source code, but it doesn’t appear to be possible 
without writing my own custom function.  Any ideas?

Thank you!

--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/29de56e899934c489630983151e28092%40ISS1.ISS.LOCAL<https://groups.google.com/d/msgid/django-users/29de56e899934c489630983151e28092%40ISS1.ISS.LOCAL?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/CAK52boX3QBmimdd3z5YSbKDOAMOeDrX6iF3NzvsLs-fNx2PO1g%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CAK52boX3QBmimdd3z5YSbKDOAMOeDrX6iF3NzvsLs-fNx2PO1g%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/e85597c0b8634f46ae5d1f6ede73abdd%40ISS1.ISS.LOCAL<https://groups.google.com/d/msgid/django-users/e85597c0b8634f46ae5d1f6ede73abdd%40ISS1.ISS.LOCAL?utm_medium=email&utm_source=footer>.

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

--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegrou

RE: Admin Email From Address

2016-11-15 Thread Matthew Pava
Thank you so much, Constantine!  That was the clue I needed.  It’s not exactly 
the cleanest solution, but it does get the job done.  I copied 
AdminEmailHandler and mail_admins and modified them appropriately to include 
the from_email address.

I had some issue with “Apps not loaded,” but all I had to do then was move 
“from django.conf import settings” to the top of the file before all other 
imports.


From: kostyak7...@gmail.com [mailto:kostyak7...@gmail.com] On Behalf Of 
Constantine Covtushenko
Sent: Tuesday, November 15, 2016 3:19 PM
To: django-users@googlegroups.com
Subject: Re: Admin Email From Address

As I know all error emails are sent within logger handler: 'mail_admins'.

I would suggest to override 'AdminEmailHandler' and 'mail_admins'.

for more information check logging 
documentation<https://docs.djangoproject.com/en/1.10/topics/logging/>.

Hope that helps

On Tue, Nov 15, 2016 at 10:31 PM, Matthew Pava 
mailto:matthew.p...@iss.com>> wrote:
The error emails only go to the admins: me.  I would not be confused because 
the subject line of the email indicates that it is coming from the Django app 
starting with [Django].  The value in receiving the emails with the user’s 
email address is so that if, for instance, the president of the company gets an 
error page or anyone else gets an error page, I can very quickly determine 
which error I should focus on by simply glancing on who the email is from.  (In 
this case, the president…)

From: kostyak7...@gmail.com<mailto:kostyak7...@gmail.com> 
[mailto:kostyak7...@gmail.com<mailto:kostyak7...@gmail.com>] On Behalf Of 
Constantine Covtushenko
Sent: Tuesday, November 15, 2016 2:27 PM

To: django-users@googlegroups.com<mailto:django-users@googlegroups.com>
Subject: Re: Admin Email From Address

Sorry but I do not see any valuable reason of doing things in such way.

Email is sent from wrong sender.
And if someone decides to email back than those user would be confused.

It is better to call things by its name.

On Tue, Nov 15, 2016 at 4:05 PM, Matthew Pava 
mailto:matthew.p...@iss.com>> wrote:
In such cases, we would have a fallback that is already established in the 
settings file.

From: django-users@googlegroups.com<mailto:django-users@googlegroups.com> 
[mailto:django-users@googlegroups.com<mailto:django-users@googlegroups.com>] On 
Behalf Of Constantine Covtushenko
Sent: Tuesday, November 15, 2016 12:46 AM
To: django-users@googlegroups.com<mailto:django-users@googlegroups.com>
Subject: Re: Admin Email From Address


Hi Matthew,

There should be considered following:
1. Not always cod runs with user interaction - worker cases
2. Not always user authenticated

With such cases who the sender should be?

Regards,
Constantine C.

On Nov 15, 2016 12:43 AM, "Matthew Pava" 
mailto:matthew.p...@iss.com>> wrote:
I would like to be able to change the ‘from’ address of the admin error emails 
in production environments to be the email address of the user that generated 
the error.  It would be convenient in triaging errors rather quickly.

I did examine the Django source code, but it doesn’t appear to be possible 
without writing my own custom function.  Any ideas?

Thank you!

--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/29de56e899934c489630983151e28092%40ISS1.ISS.LOCAL<https://groups.google.com/d/msgid/django-users/29de56e899934c489630983151e28092%40ISS1.ISS.LOCAL?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/CAK52boX3QBmimdd3z5YSbKDOAMOeDrX6iF3NzvsLs-fNx2PO1g%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CAK52boX3QBmimdd3z5YSbKDOAMOeDrX6iF3NzvsLs-fNx2PO1g%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message beca

Annotate a List of Values

2016-11-17 Thread Matthew Pava
I am trying to annotate a list of values on a queryset.
Basically, I have a model of Items that are associated many to many to Serial 
Numbers, and I want for each distinct Item the list of all Serial Numbers for 
that Item.

-- 
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/06b0691008e84a15b768abd658d1bc38%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: user object not available in template

2016-11-28 Thread Matthew Pava
Render_to_response no longer accepts a context instance parameter (or a “dirs” 
parameter).
https://docs.djangoproject.com/en/dev/releases/1.10/

I encourage you to read this document before performing an upgrade:
https://docs.djangoproject.com/en/dev/howto/upgrade-version/

In particular, read the release notes (as time consuming as it is) of each 
version between the two versions you are upgrading from and to.
https://docs.djangoproject.com/en/dev/releases/


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Drew Ferguson
Sent: Friday, November 25, 2016 5:43 PM
To: Django users
Subject: Re: user object not available in template

I just upgraded from 1.5 or something where the code worked fine

I'm not sure what has changed in 1.10 but everything is back to normal after I 
changed

def homepage(request):
return render_to_response('xstatic_homepage.html', RequestContext(request))

to

def homepage(request):
return render(request, 'xstatic_homepage.html')

Can someone explain this for me please?

On Saturday, 26 November 2016 00:25:24 UTC+1, James Bennett wrote:
Ah, never mind, misread the question.

Are you sure you're using a RequestContext?

On Fri, Nov 25, 2016 at 3:23 PM, James Bennett 
> wrote:
The auth context processor provides it, but not as a variable named 'user'; 
instead it's attached to the 'request' variable, so what you want is '{% if 
request.user.is_authenticated }}'.

On Fri, Nov 25, 2016 at 3:02 PM, Drew Ferguson > 
wrote:
Hi

Using Django 1.10

In my templates there is no user object to provide user.is_authenticated

Is there something I have to do to turn this on?

My settings has this

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]


MIDDLEWARE = [

'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
]

Thanks

Drew
--
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/0392acda-3e6d-41d6-9a6f-1b2a07f9146f%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/757507d3-bbdf-4408-9820-6f93bf069440%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/227491228cc844c99fd4aa194869f74f%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: wsgiref - When does the complexity of question require posting to the Developers or other forums?

2016-12-02 Thread Matthew Pava
For what it’s worth, I do get this error sometimes when I am running the 
development server, even in Python 3.5 and Django 1.10.  But because it’s the 
development server, I simply disregard it.
I typically only get this message when I am running several AJAX calls very 
close together.  (e.g. When I am filling out an autocomplete that queries the 
server after every key press.)

Seeing the error message, though, I wonder if it would be so hard to simply 
check if self.status is None before executing the command.


  File "/usr/lib64/python2.7/wsgiref/simple_server.py", line 33, in close
   self.status.split(' ',1)[0], self.bytes_sent
   AttributeError: 'NoneType' object has no attribute 'split'





From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of NoviceSortOf
Sent: Friday, December 2, 2016 10:58 AM
To: Django users
Subject: Re: wsgiref - When does the complexity of question require posting to 
the Developers or other forums?

Thanks for the reply.
I agree the probability of this being a bug in Django is improbable still I 
found git hub django
bug descriptions/discussions which URLs are listed in previous posts. Both of 
those URLs
listed patches to fix the situation, not directly in Django but in the WsgiRef 
component.
https://github.com/django/django/commit/2f615b10e6330d27dccbd770a4628200044acf70
https://github.com/django/django/commit/742ea51413b3aab07c6afbfd1d52c1908ffcb510

I naturally referred to them being as could not find after search of the 
internet or this forum any further info.

It would be better if traceback pointed to my code but instead Traceback now 
points to
/usr/lib/python2.7/site-packages/django/core/handlers/base.py
with the same attribute error. 'NoneType' object has no attribute 'render'.
(SEE Traceback below)

With so much of this troubleshooting being in finding the right question.
* Would issue perhaps be limited to Django’s built-in development server?
* Would using a difference Web Interface Gateway solution solve the problem?

Details follow...

Please advise


I type on the Linux server command line
# python manage.py runserver 0.0.0.0:8000
then point my browser to...
http://[MyDevelopmentServerIP]:8000/
And get the following response.


1

 2

 3

 4

 5

 6

 7

 8

 9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39


Environment:





Request Method: GET

Request URL: http://MyServer:8000/



Django Version: 1.6.12

Python Version: 2.7.5

Installed Applications:

('django.contrib.auth',

 'django.contrib.contenttypes',

 'django.contrib.sessions',

 'django.contrib.sites',

 'django.contrib.admin',

 'django.contrib.humanize',

 'django.contrib.redirects',

 'bookstor.books',

 'bookstor.registration',

 'bookstor.profiles',

 'django_extensions',

 'django.contrib.admin',

 'bookstor.cart')

Installed Middleware:

('django.middleware.common.CommonMiddleware',

 'django.contrib.sessions.middleware.SessionMiddleware',

 'django.middleware.common.CommonMiddleware',

 'django.middleware.csrf.CsrfViewMiddleware',

 'django.contrib.auth.middleware.AuthenticationMiddleware',

 'django.middleware.transaction.TransactionMiddleware',

 'django.contrib.messages.middleware.MessageMiddleware',

 'django.contrib.redirects.middleware.RedirectFallbackMiddleware')





Traceback:

File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in 
get_response

  94.  

Checkings perms results in SERVER_DOWN error

2016-12-07 Thread Matthew Pava
I am using Django-auth-ldap as my primary authentication backend.  Since using 
this package, I have noticed that our LDAP server (actually, an Active 
Directory Primary Domain Controller) sometimes cannot be reached by Django (or 
Outlook, for that matter, but that's a different problem).  Django seems to be 
trying to connect to the LDAP server whenever we are checking the permissions 
in the view or template currently being accessed by the user that is already 
logged in.

Now, I do have the standard ModelBackend set up as an alternative if the 
LDAPBackend authentication  fails.  Based on what I am reading, though, Django 
will only change backends during the authentication phase.  Am I correct on 
this?  From what I now understand and what seems to be happening, if checking 
permissions through the LDAPBackend results in an error, Django will raise that 
error and not move on to the next backend, ModelBackend.

Any ideas around this?

Thank you so much for your time.

-- 
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/44ad1bced94b4322b20fa2524559e013%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


RE: Drawback of delete all migrations file

2016-12-09 Thread Matthew Pava
If you made any of your customizations to the migrations files, then you will 
lose that information.

You may want to consider using Django’s dumpdata management command to save all 
the data on your production database (and loaddata to restore it).
https://docs.djangoproject.com/en/1.10/ref/django-admin/#dumpdata

Otherwise, flush away.  During the development of my project, at least at the 
beginning, I always deleted all of the migration files until I settled on a 
model that worked for me and I started adding my own customizations to them.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Sylvain Dégué
Sent: Friday, December 9, 2016 12:40 PM
To: Django users
Subject: Drawback of delete all migrations file

Im about to lauch a project that uses django for the api. So im only using the 
admin side for now. Ive been having problem concerning the database and forms.
Ive made many mistake while updating the database, when certain field didnt 
allow null. It caused IntegrityError, which I was able to fix

SO im thinking about reset completly my production database and remove all the 
migrations to start fresh. I dont have much data in the production database so 
its probably the best time.


Is there any drawback to flushing the database and removing the migrations files
--
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/bff6a050-8a28-48f4-abf2-57f17c3c8a04%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/fe0788257b314e4c9ebdb5a26cd62a63%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


M2M Question

2016-12-15 Thread Matthew Pava
I have a Document model that has an M2M-symmetrical field on itself.  The idea 
is that we can "link" documents to other documents.  It's very simple to find 
the linked documents of a particular document, but is there an easy way to get 
all the linked documents of the linked documents of the document in question?  
I will probably have to write my own QuerySet or ModelManager function, but I 
was just curious if Django had something built in.

For example:
A is linked to J, C, K.

è J is linked to A

è C is linked to A

è K is linked to A
B is linked to J, M, P.

è J is linked to B

è M is linked to B

è P is linked to B
C is linked to O.

è O is linked to C
D is linked to O, P, R.

è O is linked to D

è P is linked to D

è R is linked to D

So when I get the entire "chain" of documents linked to A, I would get 
something like this:
J, C, K, B, O, D, P, R, M

Since J is linked to A and B, K is linked to A, and C is linked to A and O and 
O is linked to D, and D is linked to O and P, R is linked to D and P is linked 
to B which is linked to M (and J).
Hmmm...my contrived example exploded on me more than I intended...

-- 
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/7a3247baf2234f8ab3a7a4db40bcf8c5%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


  1   2   3   4   >