From old-school Post/Redirect/Get to modern web

2017-07-24 Thread guettli
I use Post/Redirect/Get  
since several years. I use simple HTML forms (via ModelForm) with a plain 
old submit-button.

Above pattern works.

But I think the web of the future works different.

Up to now my web application sends html to the web client. I think modern 
web applications
don't send html, they send data (in json format).

I guess in the future web clients render the (json) data using a 
library/framework.

For me this client-side rendering is completely new. I have no clue where 
to start this adventure.

I guess django-rest-framework could help on the server side

Has anyone hints or practical experience?



-- 
You received this message because you are subscribed to the Google 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/9151365a-2497-4db4--90ea50a350eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: From old-school Post/Redirect/Get to modern web

2017-07-24 Thread Christian Ledermann
https://blog.levit.be/new-django-admin-with-emberjs-what-are-the-news/
could give you some insights

HTH

On 24 July 2017 at 11:36, guettli  wrote:
> I use Post/Redirect/Get since several years. I use simple HTML forms (via
> ModelForm) with a plain old submit-button.
>
> Above pattern works.
>
> But I think the web of the future works different.
>
> Up to now my web application sends html to the web client. I think modern
> web applications
> don't send html, they send data (in json format).
>
> I guess in the future web clients render the (json) data using a
> library/framework.
>
> For me this client-side rendering is completely new. I have no clue where to
> start this adventure.
>
> I guess django-rest-framework could help on the server side
>
> Has anyone hints or practical experience?
>
>
>
> --
> You received this message because you are subscribed to the Google 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/9151365a-2497-4db4--90ea50a350eb%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
Best Regards,

Christian Ledermann

Newark-on-Trent - UK
Mobile : +44 7474997517

https://uk.linkedin.com/in/christianledermann
https://github.com/cleder/


<*)))>{

If you save the living environment, the biodiversity that we have left,
you will also automatically save the physical environment, too. But If
you only save the physical environment, you will ultimately lose both.

1) Don’t drive species to extinction

2) Don’t destroy a habitat that species rely on.

3) Don’t change the climate in ways that will result in the 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/CABCjzWppWAEf6y%2BOt-fXM3W%2Bqo78FCk7Fr8wdfEgCJExFk9d8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


ModelForm validation of foreign keys - extra database queries and performance bottleneck

2017-07-24 Thread johan de taeye

I have a model that has a foreign key relation to a number of other objects.
When saving an instance of this model from the admin (or a ModelForm), I 
see plenty of extra and redundant database calls. 
For a single record it wouldn't make much of a difference, but when using 
the same ModeForm to do some batch upload these become the bottleneck in 
the process.

Has anyone bumped into the same performance bottleneck? 
Has anyone developed some solution for this?

By logging all database queries and some digging in the code, here's my 
analysis of what is happening:

   1. Open the admin editing screen for a single record.  
   I leave all fields to the original value, except for a field (not one of 
   the foreign key fields)
   2. When saving the record, the first query reads the existing record:
 select field1, field2, field3,  from mytable;
   3. During the form/model validation, I get an extra database query for 
   each of the foreign key fields.
   It is generated from the to_python method 
   of django.forms.models.ModelChoiceField:
 select field_a, field_b, field_c, field, ... from related_table 
   where pk = 'id_from_first_query';
   4. During the form/model validation, I get another database query for 
   each of the foreign key fields.
   It verifies that the values actually exists in the database:
select (1) from related_table where pk = 'value from form'; 

The queries in step 3 and 4 are redundant if the field hasn't changed. The 
first query gives enough data to allow us to verify that the new form value 
and the foreign key field on the existing instance are equal. I am using 
django 1.11.

The same queries, except 2, are executed when I create a new record. The 
queries in step 4 are redundant then - we just retrieved the values from 
the database.

Looking forward to any insights and hints...


Johan

-- 
You received this message because you are subscribed to the Google 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/48bfca91-8750-4ad0-9c50-1ffc3c2fdb5f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Multiple User Types in Django 1.11

2017-07-24 Thread stan
What is the best way to create multiple user types in Django 1.11?

For example, an e-learning platform will need 2 user models: Students and 
Teachers, which have different permissions and different attributes/methods

-- 
You received this message because you are subscribed to the Google 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/a5127741-73a1-4a34-8e4e-ab753c6aab7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


The best way to use AMP of google with Django

2017-07-24 Thread carlos
Hi, i have blogs with Django i need use AMP (https://www.ampproject.org/)

What is the best way to use it with django, someone has an example
To apply with django or idea, book, tutorial etc. i read, see this projects
https://github.com/shtalinberg/django-amp-tools

But not working with django 1.11.x, any idea manual used

thanx

-- 
att.
Carlos Rocha

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


Re: The best way to use AMP of google with Django

2017-07-24 Thread Jani Tiainen
Hi

I really don't know what AMP is but Django templates can be used to output
any text you want to. Whout extra work.

If you need content negotiation that is also relatively simple to do.

24.7.2017 20.55 "carlos"  kirjoitti:

> Hi, i have blogs with Django i need use AMP (https://www.ampproject.org/)
>
> What is the best way to use it with django, someone has an example
> To apply with django or idea, book, tutorial etc. i read, see this projects
> https://github.com/shtalinberg/django-amp-tools
>
> But not working with django 1.11.x, any idea manual used
>
> thanx
>
> --
> att.
> Carlos Rocha
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAM-7rO2%3D1PLLeE_BwbttBoFPd6zu8GfeG25XYAXdqYnkU
> jiC5Q%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/CAHn91od6Fr1qgdS8q2JQOvYs8k10-CjmR13P-upT8uyey69WWw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple User Types in Django 1.11

2017-07-24 Thread Russell Keith-Magee
Short version: You don’t.

Your site may have 2 types of user - but that doesn’t mean you have 2 user 
models. The user model is primarily for determining authentication; 
authorisation can be handled separately. 

So - set up a user model the way you normally would; then define a Teacher 
model and and Student model, each with a OneToOneKey to User. The user logs in, 
and you can determine what type of user they are by looking for the existence 
of a “teacher” or “student” attribute. You can then perform permission checks 
etc as appropriate by looking for user.student. or 
user.teacher..

As a side effect, this also allows for the edge case where a student is *also* 
a teacher - e.g., at a university, I might be studying business while teaching 
computer science.

Yours,
Russ Magee %-)

> On 24 Jul 2017, at 7:09 PM, stan  wrote:
> 
> What is the best way to create multiple user types in Django 1.11?
> 
> For example, an e-learning platform will need 2 user models: Students and 
> Teachers, which have different permissions and different attributes/methods
> 
> -- 
> You received this message because you are subscribed to the Google 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/a5127741-73a1-4a34-8e4e-ab753c6aab7d%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/13239165-5A74-4409-ABEB-7A01D58E5E50%40keith-magee.com.
For more options, visit https://groups.google.com/d/optout.


How can I auto-fill a field in the model without showing a form field to the user?

2017-07-24 Thread Alexander Joseph
I'm new to django, but coming from php I think its the greatest thing ever.

I have a model for Invoices ...

{{{
from django.conf import settings
from django.db import models
from django.core.urlresolvers import reverse
#from django.contrib.auth.models import User

# Create your models here.
class Invoice(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
their_company = models.CharField(max_length=255)
invoice_number = models.CharField(max_length=50, default='')
bill_to = models.CharField(max_length=255, default='')
created_by = models.ForeignKey(settings.AUTH_USER_MODEL)

class Meta:
ordering = ['invoice_number', ]

def __str__(self):
return self.invoice_number

def get_absolute_url(self):
return reverse("accounting:invoices:detail", kwargs={"pk": self.pk})
}}}

right now the user has to put in the invoice number themselves. I want to 
not give the user that option though - I'd like to autofill that field in 
the database with a concatenation of the 2 digit year (17) plus 2 digit 
month (07) plus 2 digit day (24) and then a 2 digit auto increment for 
every invoice created on that specific date so the first invoice created 
today would be 17072401 and the second would be 17072402, etc. I'm guessing 
I need a field just for the date and another for the iteration of each 
invoice.

Can anyone give me some direction on this? First I'm not sure how to 
autofill a field in the database without getting the input from the user, 
and I'm also not sure how I would do the concatenation with the right 
numbers. Thanks for your help

-- 
You received this message because you are subscribed to the Google 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/b1d1f963-89dd-4891-b617-1e81b7e7f655%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.