Re: How to find a view in a complex web application

2015-05-04 Thread guettli
Hi Derek,

yes, your previous answer already contained information what the database 
schema could be.

This schema is not related to my application at all. At least I think so. 
This would be generic and reusable.

I think there is a better solution than starting plumbing this for myself.

Maybe it is better if we would use one of the many navigation apps for our 
project.

https://www.djangopackages.com/grids/g/navigation/

Maybe one of those already stores the relevant data in the database 

I will post here, if I found a solution.

Regards,
  Thomas Güttler


Am Donnerstag, 30. April 2015 18:29:30 UTC+2 schrieb Derek:
>
> Hi Thomas
>
> I do not I understand your question; I made a suggestion previously for 
> what fields you might need in this 'metadata' model, and you can add or 
> change as needed.  I do not know what your project looks like, so I cannot 
> comment on what the rest of your database should contain.
>
> Derek
>
> On Thursday, 30 April 2015 13:26:25 UTC+2, guettli wrote:
>>
>> Hi Derek,
>>
>> yes, your idea looks good.
>>
>> Next question would be: How to lay out the database structure (models)?
>>
>> Regards,
>>   Thomas
>>
>> Am Dienstag, 28. April 2015 16:04:35 UTC+2 schrieb Derek:
>>>
>>> A quick "brain storm"...
>>>
>>> One idea could be to keep all the metadata for your views - their full 
>>> name; abbreviated name; aliases (alternate names); URL; keywords; and 
>>> categories etc. in a single table.  You could then use this table to 
>>> generate *multiple* possible ways for a user to "find" the view they need.
>>>
>>> For example - you could present a list of categories (and 
>>> sub-categories, and sub-sub-categories) which could be presented in a 
>>> expandable list (jQuery-style).
>>>
>>> You could create a tag-cloud and allow a user to 'expand' a single tag 
>>> into related-views.
>>>
>>> You could allow a user to create their own tags for searching and 
>>> display (in a many-to-many table linked to user).
>>>
>>> You could allow a user to "favourite" some of the views and allow the 
>>> user to easily see (list/sort/search) those.
>>>
>>> And, of course, a simple search button could be created to allow an 
>>> 'incremental' display (auto-complete Google-style) of all possible matches 
>>> from all fields in your table...
>>>
>>> I am sure there are other ways you could think of to generate navigation 
>>> options, including fancy graphic ones!
>>>
>>> You would have to 'admin' this table of course, but the data in it could 
>>> be changed dynamically (e.g. adding more categories and aliases) without 
>>> affecting the logic of your app.
>>>
>>> [Hey - this could even make a cool app on its own!]
>>>
>>> Hope these ideas help  my project is a just a boring menu-driven one.
>>>
>>> Derek
>>>
>>>
>>> On Tuesday, 28 April 2015 11:27:47 UTC+2, guettli wrote:

 We have a complex intranet application.

 It has many view.

 The problem: How to find the view a user wants to use?

 A huge sitemap HTML does not help.

 Is there a way to search the matching view?

 Maybe even with auto complete?




-- 
You received this message because you are subscribed to the Google 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/afb9bf35-4c10-4f39-aa4a-629177245102%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Deploying django

2015-05-04 Thread João Marques
Thanks for the answer, what are this configuration files that you speak of? 
I really don't know much about this whole deployment thing. From what i 
remenber i configured apache configuration and something called 
available-sites...


On Sunday, 3 May 2015 22:24:07 UTC+1, Fellipe Henrique wrote:
>
> Hey man!!
>
> In my setup, I use this: Gunicorn + nginx + supervisor
>
> Please, share your confs files.. without them we can't help a lot!
>
> T.·.F.·.A.·. S+F
> *Fellipe Henrique P. Soares*
>
> e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 
> 's/(.)/chr(ord($1)-2*3)/ge'
> *Blog: http://fhbash.wordpress.com/ *
> *GitHub: https://github.com/fellipeh *
> *Twitter: @fh_bash*
>
> On Sun, May 3, 2015 at 5:08 PM, João Marques  > wrote:
>
>> Hey there guys, I'm starting to lose my hope in deploying my django 
>> project to a vps. Here is what I've done so far (notice that i'm a newbie 
>> and this is the first time): I've created my virtualenv and installed pip, 
>> django, mysqldb package and nginx (i think). I followed this tutorial: 
>> https://www.digitalocean.com/community/tutorials/how-to-deploy-a-local-django-app-to-a-vps
>>
>> There were, although a few missing points on the tutorial like on the 
>> gunicorn set-up, the command that's listed on the tutorial is outdated and, 
>> even with the help of gunicorn's documentation, I couldn't figure it out.
>>
>> Now what happens when I run the server in "debug = False" is an error 
>> 500. Without the "debug = False" I get this:'Empty static prefix not 
>> permitted'.
>>
>> Can you recommend me a good tutorial for me to follow?
>>
>> ps. I still need to use this http://37.59.114.190:8001/ with the port, 
>> but I believe that is because of the gunicorn that i didn't set up.
>> Thank you so much for your time,
>>
>> João Marques
>>
>> -- 
>> You received this message because you are subscribed 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/79f73903-55d1-4c4c-a1d1-4a477bfd41ff%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b8f0a752-4a83-48d3-aaea-99987c171dce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Deploying django

2015-05-04 Thread João Marques
Oh I get it. I have a few questions:

1. Wheres should I configure my nginx?

2. Is there a any problem with my project folder structure? Because I do 
have my templates outside the static folder...

├── costum
├── manage.py
├── psi
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── middlewares.py
│   ├── middlewares.pyc
│   ├── __pycache__
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── static
│   ├── bower_components
│   ├── circle-progress.js
│   ├── css
│   ├── dist
│   └── js
├── static-root
├── templates
│   ├── admin-panel
│   ├── base.html
│   ├── home.html
│   ├── renderSolution.html
│   └── runAlgorithm.html
└── teste1
├── admin.py
├── admin.pyc
├── algorithm.py
├── binariesExchange.py
├── binaries.py
├── fitness.py
├── __init__.py
├── __init__.pyc
├── migrations
├── models.py
├── models.pyc
├── __pycache__
├── tests.py
└── views.py


On Monday, 4 May 2015 00:16:00 UTC+1, Mike Dewhirst wrote:
>
> On 4/05/2015 6:08 AM, João Marques wrote: 
> > Now what happens when I run the server in "debug = False" is an error 
> > 500. Without the "debug = False" I get this:'Empty static prefix not 
> > permitted'. 
>
> Googling that error brings up a few results. It seems to indicate a 
> problem with STATIC_ROOT and STATIC_URL when DEBUG is true and/or 
> misconfiguration of Nginx when DEBUG is false. 
>
> https://docs.djangoproject.com/en/1.8/howto/static-files/#deployment 
>
> Running collectstatic drops all your static files into the STATIC_ROOT 
> directory on the server and that is where Nginx has to find them. The 
> way it works is that when a user requests a static file in a URL, Nginx 
> has to recognise the URL prefix to the static file named. The Nginx 
> config you need is to make the recognised URL prefix point to a real 
> location on the server (ie where collectstatic previously put the static 
> files) 
>
> hth 
>
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a7a5ded5-d804-4bcd-9327-ec1bd385707b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Fields outside Aggregation functions

2015-05-04 Thread Alex-droid AD


There is example in Django documentation about using Aggregate and Annotate 
clauses

The same rules apply to the aggregate() clause. If you wanted to know the 
lowest and highest price of any book that is available for sale in a store, 
you could use the aggregate:

Store.objects.annotate(min_price=Min('books__price'), 
max_price=Max('books__price'))

Store.objects.aggregate(min_price=Min('books__price'), 
max_price=Max('books__price'))


By this string of code I'll get min/max price each of book in each store
But I won't see name or id of book, which was selected during use of 
aggregation (max or min)
So the question... How can I get records

storemin/max price*book ???*





-- 
You received this message because you are subscribed to the Google 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/814ef5a3-6e2b-4054-9a1c-6ca127c2d527%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Deploying django

2015-05-04 Thread Mike Dewhirst

On 4/05/2015 6:43 PM, João Marques wrote:

Oh I get it. I have a few questions:

1. Wheres should I configure my nginx?


/etc/nginx (probably)

This is part of my nginx config ...


location /static/ {
root/home/mike/envs/myproject/static;
access_log  off;
log_not_found   off;
}

location /robots.txt {
root/home/mike/envs/myproject/static/robots;
access_log  off;
log_not_found   off;
}

location /favicon.ico {
root/home/mike/envs/myproject/static/img;
access_log  off;
log_not_found   off;
}





2. Is there a any problem with my project folder structure? Because I do
have my templates outside the static folder...


Templates are not static files. They are part of Django's page rendering 
mechanism. Static files are css, images and javascript plus other media 
or files which don't need to be served *by* Django. You call such things 
in your software by either naming them directly in your templates (like 
css, js and images) or having variables in your templates which name 
such static files.


Check the documentation starting at 
https://docs.djangoproject.com/en/1.8/topics/templates/


I haven't had time to look at your project folder beyond noticing some 
"interesting" folder names and files.


You should work through the tutorial (if you haven't already) and 
discover the typical folder layout. It is easier to get the hang of 
things if you stick with the conventional layout until you find a strong 
reason to do things differently.


Good luck

Mike



├── costum
├── manage.py
├── psi
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── middlewares.py
│   ├── middlewares.pyc
│   ├── __pycache__
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── static
│   ├── bower_components
│   ├── circle-progress.js
│   ├── css
│   ├── dist
│   └── js
├── static-root
├── templates
│   ├── admin-panel
│   ├── base.html
│   ├── home.html
│   ├── renderSolution.html
│   └── runAlgorithm.html
└── teste1
 ├── admin.py
 ├── admin.pyc
 ├── algorithm.py
 ├── binariesExchange.py
 ├── binaries.py
 ├── fitness.py
 ├── __init__.py
 ├── __init__.pyc
 ├── migrations
 ├── models.py
 ├── models.pyc
 ├── __pycache__
 ├── tests.py
 └── views.py


On Monday, 4 May 2015 00:16:00 UTC+1, Mike Dewhirst wrote:

On 4/05/2015 6:08 AM, João Marques wrote:
 > Now what happens when I run the server in "debug = False" is an
error
 > 500. Without the "debug = False" I get this:'Empty static prefix not
 > permitted'.

Googling that error brings up a few results. It seems to indicate a
problem with STATIC_ROOT and STATIC_URL when DEBUG is true and/or
misconfiguration of Nginx when DEBUG is false.

https://docs.djangoproject.com/en/1.8/howto/static-files/#deployment


Running collectstatic drops all your static files into the STATIC_ROOT
directory on the server and that is where Nginx has to find them. The
way it works is that when a user requests a static file in a URL, Nginx
has to recognise the URL prefix to the static file named. The Nginx
config you need is to make the recognised URL prefix point to a real
location on the server (ie where collectstatic previously put the
static
files)

hth

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 http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/a7a5ded5-d804-4bcd-9327-ec1bd385707b%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 http://groups.google.com/group/django-users.
To view this discussion on t

Re: Leveraging the ORM for very complex queries

2015-05-04 Thread Suriya Subramanian
Hi Russ,

Thank you for your answer. I am aware of raw. However, that's now what I am 
looking for. Let me give a few examples of queries that I would like to 
write:

1) Window functions over an ORM query:
SELECT "date", SUM("weight__sum") OVER (ORDER BY "date")
FROM
(
MyModel.objects.values('date').annotate(Sum('weight')).query
) T

2) Join of two ORM queries
( complex ORM query ) NATURAL JOIN ( complex ORM query  )

Writing query 1 and 2 fully in SQL is painful, since they leverage a lot of 
Python and ORM logic (for example: parsing URL arguments and filtering). 
Composing SQL and ORM, even if it means having to deal with the guts of 
SQLCompiler.as_sql() seems to be a decent solution for me. I am asking if 
there any best practices to follow or gotchas to watch out for.

Thanks,
Suriya

On Monday, May 4, 2015 at 5:35:50 AM UTC+5:30, Russell Keith-Magee wrote:
>
> Hi Suriya,
>
> It sounds like you're looking for raw SQL queries:
>
> https://docs.djangoproject.com/en/1.8/topics/db/sql/#performing-raw-queries
>
> This allows you to issue a SQL query in SQL, rather than trying to bend 
> the ORM to meet some complex query requirement.
>
> You can't compose a raw query like a normal Django ORM query (e.g., you 
> can't add a filter clause to an raw query), but a raw query object behaves 
> exactly like queryset when it returns results - it is iterable, it returns 
> full Django objects, and so on. 
>
> Yours,
> Russ Magee %-)
>
> On Sun, May 3, 2015 at 9:22 AM, Suriya Subramanian  > wrote:
>
>> Hello,
>>
>> I have to write some complex SQL queries that I am unable to express 
>> using the ORM. I construct these complex queries by writing a few simple 
>> ORM queries, getting the SQL using QuerySet.query and combining them with 
>> various SQL operators manually. These hand-crafted queries are not very 
>> flexible because it is very easy to modify the final SQL.
>>
>> My question: Is there a way to programmatically construct the complex 
>> queries. I see that I can get the generated SQL and parameters by invoking 
>> SQLCompiler.as_sql(). Can I invoke as_sql() on the individual query sets 
>> and then construct the complex query? What are some gotchas that I need to 
>> watch out for?
>>
>> Thanks,
>> Suriya Subramanian
>>
>> -- 
>> You received this message because you are subscribed 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/b4465893-6d08-4ed3-babd-1f6e0f0f52ab%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fcb71fe4-cf87-40f6-ad5c-4792e9261754%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to represent a calendar month as a field in django models

2015-05-04 Thread Matthys Kroon
Hi,

I'm specifically looking at only situations where the year and month alone
are significant.

The downside I see with using a DateField and forcing the day to the first
of the month, with custom widget etc. is that somebody looking at the
database may not realize that something unusual is going on and I'm not
sure how I would go about finding the month x months before or after after
a given month ... solutions like

where 12 * year(t1.month_field) + month(t1.month_field) = 12 *
year(t2.month_field) + month(t2.month_field) + x

come to mind for sql but not sure how this would translate into django. Not
that I'm saying it is not the correct solution, all of the options I
considered have some downside.

The logic for adding and subtracting these "months" requires something like
timedelta(month=2), which doesn't exist in the standard library as far as I
know - though I'm not an expert.

There are recipes on stackoverflow for incrementing months though not very
elegant.

Thanks for your interest!

Matthys

On Mon, May 4, 2015 at 5:47 AM, Mike Dewhirst  wrote:

> On 4/05/2015 12:31 PM, Tom Lockhart wrote:
>
>> Surely that would destroy data which wouldn’t be desirable.
>>>
>> I’m not sure how that follows.
>>
>
> If you are adjusting a date from whatever it actually is to the first of
> the month you lose the actual date.
>
> Although the question does not state
>
>> it explicitly, I believe that the OP is interested in dates for which
>> only the year and month are significant.
>>
>
> Granted. If that is correct.
>
> Saving the month as a
>
>> separate field seems to overly complicate the problem if any
>> date/time arithmetic is required.
>>
>
> Saving a date adjusted to the first of the month also involves a
> complication - or at least some work - then you extract the month to be
> displayed or queried.
>
> Extracting the month from a date is the same no matter whether it is the
> first or the ninth.
>
> Who knows when the requirements will change but you can guarantee they
> will change and Murphy's law says it will happen after you have thrown data
> away.
>
> Anyway, your choices are to calculate it every time you need it or do it
> once and use it thereafter. The right choice will depend on the
> requirements. Which will change.
>
> Cheers
>
> Mike
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/vmsiHYzI-gg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5546EBE6.1010705%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMtJH%2BvnCsSqCsAOm9R-a2jsqWoCz9AQi19Cow75-4qQkmkQhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to represent a calendar month as a field in django models

2015-05-04 Thread Erik Cederstrand

> Den 04/05/2015 kl. 13.26 skrev Matthys Kroon :
> 
> I'm specifically looking at only situations where the year and month alone 
> are significant.
> 
> The downside I see with using a DateField and forcing the day to the first of 
> the month, with custom widget etc. is that somebody looking at the database 
> may not realize that something unusual is going on and I'm not sure how I 
> would go about finding the month x months before or after after a given month 
> ... solutions like
> where 12 * year(t1.month_field) + month(t1.month_field) = 12 * 
> year(t2.month_field) + month(t2.month_field) + x
> come to mind for sql but not sure how this would translate into django. Not 
> that I'm saying it is not the correct solution, all of the options I 
> considered have some downside.

Python stdlib doesn't support operating on months the way I think you expect. 
If you want to truly only operate on years and month values, then I think the 
most Pythonic/Djangoic way is to create your own Month model/class (unless you 
want to marry ourself to PostgreSQL and its' tuple type). The math to 
add/subtract months is very simple:


class Month(models.Model):
year = models.IntegerField()
month = models.PositiveSmallIntegerField()

def add_months(self, n):
assert n >= 0
dy, dm = divmod(self.month + n, 12)
self.year += dy
self.month += dm

# Expand as needed with __add__, __sub__, remove_months() etc.


> The logic for adding and subtracting these "months" requires something like 
> timedelta(month=2), which doesn't exist in the standard library as far as I 
> know - though I'm not an expert.
> 
> There are recipes on stackoverflow for incrementing months though not very 
> elegant.

That's because incrementing months is ambiguous when operating on actual 
datetimes. timedelta(months=2) is nonsense because months have different 
lengths. Adding 1 month to March 2 would mean April 2 to most people, but what 
about January 31 (let's ignore for a moment that both PHP and MySQL accept 
February 31 as a valid date)? Do you want February 28 (or possibly 29), or 
March 2 (or 3), or possibly 4 weeks ahead?

Erik

-- 
You received this message because you are subscribed to the Google 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7399E8A3-DC57-4709-B280-65BA11465439%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: How to represent a calendar month as a field in django models

2015-05-04 Thread Erik Cederstrand

> Den 04/05/2015 kl. 14.21 skrev Erik Cederstrand :
> 
> class Month(models.Model):
>year = models.IntegerField()
>month = models.PositiveSmallIntegerField()
> 
>def add_months(self, n):
>assert n >= 0
>dy, dm = divmod(self.month + n, 12)
>self.year += dy
>self.month += dm

Sorry, that's supposed to be:

def add_months(self, n):
assert n >= 0
dy, self.month = divmod(self.month + n, 12)
self.year += dy


Disclaimer: This possibly only applies to the Gregorian calendar. Read up on 
the others as needed: http://en.wikipedia.org/wiki/List_of_calendars :-)

Erik

-- 
You received this message because you are subscribed to the Google 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/B025BC73-DE58-4E4F-9F55-B94CC990381E%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Fields outside Aggregation functions

2015-05-04 Thread Mario Gudelj
Can you perhaps order by price and get first and last items?
On 4 May 2015 8:48 pm, "Alex-droid AD"  wrote:

>
>
> There is example in Django documentation about using Aggregate and
> Annotate clauses
>
> The same rules apply to the aggregate() clause. If you wanted to know the
> lowest and highest price of any book that is available for sale in a store,
> you could use the aggregate:
>
> Store.objects.annotate(min_price=Min('books__price'), 
> max_price=Max('books__price'))
>
> Store.objects.aggregate(min_price=Min('books__price'), 
> max_price=Max('books__price'))
>
>
> By this string of code I'll get min/max price each of book in each store
> But I won't see name or id of book, which was selected during use of
> aggregation (max or min)
> So the question... How can I get records
>
> storemin/max price*book ???*
>
>
>
>
>
>  --
> You received this message because you are subscribed to the Google 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/814ef5a3-6e2b-4054-9a1c-6ca127c2d527%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHqTbjm0jTf26vezq485U4YDQAJq0udfPjg2EoL%3D7NAQeTd7sg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Fields outside Aggregation functions

2015-05-04 Thread Carsten Fuchs

Hi Alex,

Am 04.05.2015 um 12:48 schrieb Alex-droid AD:

So the question... How can I get records

storemin/max price */_book ???_/*


I recently had the same question, please see this thread:
https://groups.google.com/forum/#!topic/django-users/adRe2_BWMz0

If you ever find a more direct solution than the one mentioned there, please 
let me know!

Best regards,
Carsten

--
You received this message because you are subscribed to the Google 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5547776B.2070100%40cafu.de.
For more options, visit https://groups.google.com/d/optout.


Re: Fields outside Aggregation functions

2015-05-04 Thread Alex-droid AD
I didn't quite understand have I sent the answer to Somecallitblues...
So write it once more

Forgot about Stores...
Let's look at Publisher and Book (those of Django documentation described)
Here is table beneath for example:
*Publisher*
   Publisher-a   Publisher-b   *Book*   id   2 book_1 1$ Publisher-a  7 
book_2 2$ Publisher-b  9 book_3 0,5$ Publisher-a  14 book_2 4$ Publisher-b 

If I'll write something like
*Publisher.objects.annotate(pr_max=Max('book__price'))*
I'll get (as I understand):
*Publisher   pr_max*
*Publisher-a; 1$*
*Publisher-b; 4$*

But I want to see wich book was selected by Max() function:
*Publisher   pr_maxbook_id*
*Publisher-a; 1$;   2*
*Publisher-b; 4$;  14*


On Monday, May 4, 2015 at 1:48:30 PM UTC+3, Alex-droid AD wrote:
>
>
>
> There is example in Django documentation about using Aggregate and 
> Annotate clauses
>
> The same rules apply to the aggregate() clause. If you wanted to know the 
> lowest and highest price of any book that is available for sale in a store, 
> you could use the aggregate:
>
> Store.objects.annotate(min_price=Min('books__price'), 
> max_price=Max('books__price'))
>
> Store.objects.aggregate(min_price=Min('books__price'), 
> max_price=Max('books__price'))
>
>
> By this string of code I'll get min/max price each of book in each store
> But I won't see name or id of book, which was selected during use of 
> aggregation (max or min)
> So the question... How can I get records
>
> storemin/max price*book ???*
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/409e63a3-e2c1-4b48-a417-3bb69e3d860a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


GUI with web-browser using Django, Python 3

2015-05-04 Thread Aura


I want to make a py-file by GUI. The GUI I want is based on web-browser 
(chrome, safari). So I use Django.

The step-by-step idea is:

   1. 
   
   I open the web-browser (as GUI, not to access internet). On the 
   web-browser, there are two blanks and a "Generate" button, like
   
   a = ??
   
   filename = ??
   
   "Generate"
   
   (Here ?? is blank waiting for filling.)
   2. 
   
   I fill like: a = [1,2,3,4], and filename = MyFile
   3. 
   
   Click the "Generate" button
   
   Then A py-file "MyFile.py" is generated in an aimed folder. In the file, 
   there is a python code
   
   a = [1,2,3,4]
   
   4. 
   
   I plot a figure by
   
   import matplotlib.pyplot as plt
   plt.plot(a,a)
   
   It will generate a figure. I want this figure to be shown on the 
   web-browser.
   
I am using Python 3.

Can you please show me how to do the 4 steps with Django? 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d4a8bc37-a838-40a1-ac21-48ebd335d8d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to represent a calendar month as a field in django models

2015-05-04 Thread Matthys Kroon
Hi Erik,

Thanks for your reply.

I'm aware of the problems with timedelta(months=2), since the length of a
month is not fixed, a length of time specified in months is ambiguous.
Though months do have an internally consistent algebra as you point out and
people often refer to time-periods in month without any real-world
confusion. I agree it is possible to create a class modelling this
behaviour.

The downside to creating a new classt, is that all the existing
date-related functionality in the standard library and django is lost and
has to be rewritten or wrapped somehow.

I think I'll just have to look at my use-cases and pick the option that
most easily facilitates those uses.

Cheers,



On Mon, May 4, 2015 at 2:30 PM, Erik Cederstrand 
wrote:

>
> > Den 04/05/2015 kl. 14.21 skrev Erik Cederstrand <
> erik+li...@cederstrand.dk>:
> >
> > class Month(models.Model):
> >year = models.IntegerField()
> >month = models.PositiveSmallIntegerField()
> >
> >def add_months(self, n):
> >assert n >= 0
> >dy, dm = divmod(self.month + n, 12)
> >self.year += dy
> >self.month += dm
>
> Sorry, that's supposed to be:
>
> def add_months(self, n):
> assert n >= 0
> dy, self.month = divmod(self.month + n, 12)
> self.year += dy
>
>
> Disclaimer: This possibly only applies to the Gregorian calendar. Read up
> on the others as needed: http://en.wikipedia.org/wiki/List_of_calendars
> :-)
>
> Erik
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/vmsiHYzI-gg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/B025BC73-DE58-4E4F-9F55-B94CC990381E%40cederstrand.dk
> .
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMtJH%2Bs7gvLj%2BiixemRZLqsurC7fsL3mDtBQ7rirPK%3DAwzJ2YQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django 1.8 customize site title

2015-05-04 Thread André Luiz
You can do it in in urls.py for example[1]

[1]: https://gist.github.com/dvl/0bed149bee4556b32d7a

2015-05-02 5:55 GMT-03:00 drakkan :

> Hi,
>
> I would like to customize django 1.8 site title without override the
>  template using AdminSite,
>
> I customized AdminSite as per doc here:
>
>
> https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#customizing-the-adminsite-class
>
> this seems to work, however the html title still has "Django
> administration",
>
> I added site_header and site_title to AdminSite, is this a bug or am I
> doing something wrong?
>
> here is the html
>
> Django administration | MyCustomTitle
> 
>
>
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6668d66c-4235-47a0-933c-0a81e50142b2%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAL6LtmdMNFamObwqFdwreHsbun3%3D2WOCt%2BYOr_cjs%2BBj_s1rFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: GUI with web-browser using Django, Python 3

2015-05-04 Thread Gergely Polonkai
Hello,

you should walk through the Django tutorial[1] to get as idea on how to use
it. However, if this is the sole problem, I think Django is overkill, a
pure WSGI page would suffice.

Best,
Gergely

[1] https://docs.djangoproject.com/en/1.8/intro/tutorial01/
On 4 May 2015 17:28, "Aura"  wrote:

> I want to make a py-file by GUI. The GUI I want is based on web-browser
> (chrome, safari). So I use Django.
>
> The step-by-step idea is:
>
>1.
>
>I open the web-browser (as GUI, not to access internet). On the
>web-browser, there are two blanks and a "Generate" button, like
>
>a = ??
>
>filename = ??
>
>"Generate"
>
>(Here ?? is blank waiting for filling.)
>2.
>
>I fill like: a = [1,2,3,4], and filename = MyFile
>3.
>
>Click the "Generate" button
>
>Then A py-file "MyFile.py" is generated in an aimed folder. In the
>file, there is a python code
>
>a = [1,2,3,4]
>
>4.
>
>I plot a figure by
>
>import matplotlib.pyplot as plt
>plt.plot(a,a)
>
>It will generate a figure. I want this figure to be shown on the
>web-browser.
>
> I am using Python 3.
>
> Can you please show me how to do the 4 steps with Django? 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d4a8bc37-a838-40a1-ac21-48ebd335d8d8%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBUKG73S-DPWpMibwas3hSyPn4i%2Buj1p_o64bQfzmzZ8yFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Leveraging the ORM for very complex queries

2015-05-04 Thread Michael Manfre
The internals of the ORM are deemed a private API and have undergone 
significant changes in the past without being constrained by the two 
release deprecation cycle. As some one who was forced to write query 
construction code based upon Django internals, my recommendation is to only 
do that if you have no other choice. You will eventually get hit by a 
change in a subsequent release of Django that forces you to remain on a no 
longer supported version of Django while you update the hack for the new 
version of Django or (better) rewrite it to use supported APIs.

Regards,
Michael Manfre

On Monday, May 4, 2015 at 7:17:49 AM UTC-4, Suriya Subramanian wrote:
>
> Hi Russ,
>
> Thank you for your answer. I am aware of raw. However, that's now what I 
> am looking for. Let me give a few examples of queries that I would like to 
> write:
>
> 1) Window functions over an ORM query:
> SELECT "date", SUM("weight__sum") OVER (ORDER BY "date")
> FROM
> (
> MyModel.objects.values('date').annotate(Sum('weight')).query
> ) T
>
> 2) Join of two ORM queries
> ( complex ORM query ) NATURAL JOIN ( complex ORM query  )
>
> Writing query 1 and 2 fully in SQL is painful, since they leverage a lot 
> of Python and ORM logic (for example: parsing URL arguments and filtering). 
> Composing SQL and ORM, even if it means having to deal with the guts of 
> SQLCompiler.as_sql() seems to be a decent solution for me. I am asking if 
> there any best practices to follow or gotchas to watch out for.
>
> Thanks,
> Suriya
>
> On Monday, May 4, 2015 at 5:35:50 AM UTC+5:30, Russell Keith-Magee wrote:
>>
>> Hi Suriya,
>>
>> It sounds like you're looking for raw SQL queries:
>>
>>
>> https://docs.djangoproject.com/en/1.8/topics/db/sql/#performing-raw-queries
>>
>> This allows you to issue a SQL query in SQL, rather than trying to bend 
>> the ORM to meet some complex query requirement.
>>
>> You can't compose a raw query like a normal Django ORM query (e.g., you 
>> can't add a filter clause to an raw query), but a raw query object behaves 
>> exactly like queryset when it returns results - it is iterable, it returns 
>> full Django objects, and so on. 
>>
>> Yours,
>> Russ Magee %-)
>>
>> On Sun, May 3, 2015 at 9:22 AM, Suriya Subramanian  
>> wrote:
>>
>>> Hello,
>>>
>>> I have to write some complex SQL queries that I am unable to express 
>>> using the ORM. I construct these complex queries by writing a few simple 
>>> ORM queries, getting the SQL using QuerySet.query and combining them with 
>>> various SQL operators manually. These hand-crafted queries are not very 
>>> flexible because it is very easy to modify the final SQL.
>>>
>>> My question: Is there a way to programmatically construct the complex 
>>> queries. I see that I can get the generated SQL and parameters by invoking 
>>> SQLCompiler.as_sql(). Can I invoke as_sql() on the individual query sets 
>>> and then construct the complex query? What are some gotchas that I need to 
>>> watch out for?
>>>
>>> Thanks,
>>> Suriya Subramanian
>>>
>>> -- 
>>> You received this message because you are subscribed 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/b4465893-6d08-4ed3-babd-1f6e0f0f52ab%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/682fc76f-5faa-4dd2-8297-4fb61c320ff1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to represent a calendar month as a field in django models

2015-05-04 Thread Tim Chase
On 2015-05-03 14:35, Matthys wrote:
> I posted the question also on stackoverflow:
> 
> http://stackoverflow.com/questions/30017229/how-to-represent-month-as-field-on-django-model
> 
> The question is for situations where a model instance relates to a
> specific month, but not to a specific day.

If the other suggestions don't work for you, you could store it as a
regular integer field for the number of months.  A custom widget
would allow you to create an interface to manage it, and the value
would simply be "years * 12 + months - 1" and to extract the year and
month, you'd use something like

  year, month = divmod(mymodel.my_yearmonth_field, 12)
  month += 1

It would have the peculiar side-effect that internally the month
would be represented by a value 0..11 instead of 1..12

However, it has the advantage that it's only one field in the
database and compares naturally ("ORDER BY my_yearmonth_field")

You could even fancy it up something like the below.

-tkc

from django.db import models
from django.forms import widgets

class YearMonth(object):
def __init__(self, year, month):
self.year = year
self.month = month

class YearMonthFormField(widgets.Widget):
# for implementation ideas, see
# 
https://docs.djangoproject.com/en/1.8/_modules/django/forms/extras/widgets/#SelectDateWidget
pass

class YearMonthField(models.IntegerField):
description = "A field for managing year+month without dates"
def __init__(self, *args, **kwargs):
super(YearMonthField, self).__init__(*args, **kwargs)
def to_python(self, value):
if isinstance(value, YearMonth):
return value
if value is None:
return value
year, month = divmod(value, 12)
return YearMonth(year, month + 1)
def from_db_value(self, value, expression, connection, context):
return self.to_python(value)
def get_prep_value(self, value):
return value.year * 12 + value.month - 1
def formfield(self, **kwargs):
defaults = {'form_class': YearMonthFormField}
defaults.update(kwargs)
return super(YearMonthField, self).formfield(**defaults)

class MyModel(models.Model):
my_yearmonth_field = YearMonthField()

-- 
You received this message because you are subscribed to the Google 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20150504120929.78c21193%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.


Using unaccent in order_by?

2015-05-04 Thread Neto
In Django 1.8 can use order_by(Lower('name')), has the order by unaccent 
too?

-- 
You received this message because you are subscribed to the Google 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/39f1f36e-b58f-42d4-9691-8fe6eae83cb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to show forms of formset as table

2015-05-04 Thread Himika Biswas
Hi,
I have a model in models.py - using which I have created a form in forms.py.
I am using formset in views.py
But all the fields of these forms of formset are shown vertically one after 
another like:

form1-field1
form1-field2
form1-field3
form2-field1
form2-field2
form2-field3
form3-field1
form3-field2
form3-field3

I want to show the forms as table like:

form1-field1form1-field2   form1-field3
form2-field1form2-field2   form2-field3
form3-field1form3-field2   form3-field3

Can anyone help me to do this?

With thanks & regards,
Himika.

-- 
You received this message because you are subscribed to the Google 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b13b737a-bd8d-43c9-90cb-603841634825%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to Process Multi Step Forms in Django?

2015-05-04 Thread Ken Nguyen


Thank you for the input.  I've already tried what you've suggested but 
still the same result, "Management Form Data is Missing."  It's not going 
to know the "first_name" and "last_name" the second time around since I 
have the variable

{{ info.first_name }} and {{ info.last_name }}

My* form2.html* currently looking like so:

{% for info in data %}



{{ info.first_name }}
{{ info.last_name }}


{% endfor %}


When you say inherit from form1 and just add the checkboxes, can you 
elaborate that?  How do I inherit it?  Do you mean just replicate the first 
form and add checkboxes to it?

Thanks,

Ken


On Saturday, May 2, 2015 at 1:24:22 PM UTC-7, Bernardo Brik wrote:
>
> You should add the same fields (first_name and address) to form2 and 
> render them with hidden inputs.
> You can try to make form2 inherit from form1 and just add the checkbox.
>
> On Friday, May 1, 2015 at 9:58:28 PM UTC-3, Ken Nguyen wrote:
>>
>> I've made some attempted to use formwizard but there wasn't much 
>> documentation about it so I decided to stay with the basic. I've 
>> successfully obtained and display the data from the first form to the 
>> second form and added some checkbox next to the data to allow user to 
>> choose whether to overwrite or ignore the duplicate data found in the 
>> backend process. The problem I have is the second form doesn't know how 
>> retrieve the data of the first form after hitting "Confirm" button. The 
>> form2.html template invalidated the data completely since it called itself 
>> again by the form action after submitting the data. Is there a way to solve 
>> this or a better approach to this?
>>
>> *forms.py*
>>
>> class NameForm (forms.Form): 
>> first_name = forms.CharField (required = False)
>> last_name = forms.CharField (required = False)
>>
>> class CheckBox (forms.Form):
>> overwrite = forms.BooleanField (required = False)
>>
>> views.py
>>
>> def form1 (request):
>>
>> NameFormSet = formset_factory (NameForm, formset = BaseNodeFormSet, 
>> extra = 2, max_num = 5)
>>
>> if request.method == 'POST':
>>
>> name_formset = NameFormSet (request.POST, prefix = 'nameform')
>>
>> if name_formset.is_valid ():
>> data = name_formset.cleaned_data
>>
>> context = {'data': data}
>> return render (request, 'nameform/form2.html', context)
>> else:
>> name_formset = NameFormSet (prefix = 'nameform')
>>
>>  context = {..}
>>
>>  return render (request, 'nameform/form1.html', context)
>>
>> def form2 (request):
>>
>> CheckBoxFormSet = formset_factory (CheckBox, extra = 2, max_num = 5)
>>
>> if request.method == 'POST':
>>
>> checkbox_formset = CheckBoxFormSet (request.POST, prefix = 
>> 'checkbox')
>>
>> if checkbox_formset.is_valid ():
>> data = checkbox_formset.cleaned_data
>>
>> context = {'data': data}
>> return render (request, 'nameform/success.html', context)
>>
>> else:
>> checkbox_formset = CheckBoxFormSet (prefix = 'checkbox')
>>
>>  return HttpResponse ('No overwrite data.')
>>
>>
>>
>> *form2.html*
>>
>>
>> 
>> 
>> 
>> 
>> {% load staticfiles %}
>> 
>> User Information
>> 
>> 
>> User Information:
>> 
>> 
>> 
>> 
>> First Name
>> Last Name
>> Overwrite
>> 
>> {% for info in data %}
>> 
>> {{ info.first_name }}
>> {{ info.last_address }}
>> > value="1">
>> 
>> {% endfor %}
>> 
>> 
>> 
>> 
>> 
>> Cancel
>> 
>> 
>> 
>>
>>

-- 
You received this message because you are subscribed to the Google 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/797bdc71-28e4-4277-b645-7c0be9593b27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to Process Multi Step Forms in Django?

2015-05-04 Thread Bernardo Brik
Hi Ken,
You are getting this error because you are missing this line in your
template: {{ formset.management_form }}
Take a look into the documentation:
https://docs.djangoproject.com/en/1.8/topics/forms/formsets/#using-a-formset-in-views-and-templates

You need to carry the information to your second view. If you don’t include
first_name and last_address as fields in the second form, the information
won’t get to your second view, when you post. That’s why I suggested
rendering them as hidden inputs. Your Checkbox form also need to have the
fields.

This is what I mean:

class NameForm (forms.Form):
first_name = forms.CharField (required = False)
last_name = forms.CharField (required = False)

class CheckBox (NameForm):
overwrite = forms.BooleanField (required = False)


And on the template:


{{ info.first_name }}
{{ info.last_address }}





Let me know if this helps.
cheers,

On Mon, May 4, 2015 at 3:50 PM, Ken Nguyen  wrote:

> Thank you for the input.  I've already tried what you've suggested but
> still the same result, "Management Form Data is Missing."  It's not going
> to know the "first_name" and "last_name" the second time around since I
> have the variable
>
> {{ info.first_name }} and {{ info.last_name }}
>
> My* form2.html* currently looking like so:
>
> {% for info in data %}
> 
>  ="nameform-{{ forloop.counter0 }}-first_name" type="hidden" value="{{
> info.first_name }}" />
>  name="nameform-{{
> forloop.counter0 }}-last_name" type="hidden" value="{{ info.last_name }}"
> />
> {{ info.first_name }}
> {{ info.last_name }}
>  value="1">
> 
> {% endfor %}
>
>
> When you say inherit from form1 and just add the checkboxes, can you
> elaborate that?  How do I inherit it?  Do you mean just replicate the first
> form and add checkboxes to it?
>
> Thanks,
>
> Ken
>
>
> On Saturday, May 2, 2015 at 1:24:22 PM UTC-7, Bernardo Brik wrote:
>>
>> You should add the same fields (first_name and address) to form2 and
>> render them with hidden inputs.
>> You can try to make form2 inherit from form1 and just add the checkbox.
>>
>> On Friday, May 1, 2015 at 9:58:28 PM UTC-3, Ken Nguyen wrote:
>>>
>>> I've made some attempted to use formwizard but there wasn't much
>>> documentation about it so I decided to stay with the basic. I've
>>> successfully obtained and display the data from the first form to the
>>> second form and added some checkbox next to the data to allow user to
>>> choose whether to overwrite or ignore the duplicate data found in the
>>> backend process. The problem I have is the second form doesn't know how
>>> retrieve the data of the first form after hitting "Confirm" button. The
>>> form2.html template invalidated the data completely since it called itself
>>> again by the form action after submitting the data. Is there a way to solve
>>> this or a better approach to this?
>>>
>>> *forms.py*
>>>
>>> class NameForm (forms.Form):
>>> first_name = forms.CharField (required = False)
>>> last_name = forms.CharField (required = False)
>>>
>>> class CheckBox (forms.Form):
>>> overwrite = forms.BooleanField (required = False)
>>>
>>> views.py
>>>
>>> def form1 (request):
>>>
>>> NameFormSet = formset_factory (NameForm, formset = BaseNodeFormSet, 
>>> extra = 2, max_num = 5)
>>>
>>> if request.method == 'POST':
>>>
>>> name_formset = NameFormSet (request.POST, prefix = 'nameform')
>>>
>>> if name_formset.is_valid ():
>>> data = name_formset.cleaned_data
>>>
>>> context = {'data': data}
>>> return render (request, 'nameform/form2.html', context)
>>> else:
>>> name_formset = NameFormSet (prefix = 'nameform')
>>>
>>>  context = {..}
>>>
>>>  return render (request, 'nameform/form1.html', context)
>>>
>>> def form2 (request):
>>>
>>> CheckBoxFormSet = formset_factory (CheckBox, extra = 2, max_num = 5)
>>>
>>> if request.method == 'POST':
>>>
>>> checkbox_formset = CheckBoxFormSet (request.POST, prefix = 
>>> 'checkbox')
>>>
>>> if checkbox_formset.is_valid ():
>>> data = checkbox_formset.cleaned_data
>>>
>>> context = {'data': data}
>>> return render (request, 'nameform/success.html', context)
>>>
>>> else:
>>> checkbox_formset = CheckBoxFormSet (prefix = 'checkbox')
>>>
>>>  return HttpResponse ('No overwrite data.')
>>>
>>>
>>>
>>> *form2.html*
>>>
>>>
>>> 
>>> 
>>> 
>>> 
>>> {% load staticfiles %}
>>> 
>>> User Information
>>> 
>>> 
>>> User Information:
>>> 
>>> 
>>> 
>>> 
>>> First Name
>>> Last Name
>>> Overwrite
>>> 
>>> {% for info in data %}
>>> 
>>> {{ info.first_name }}
>>> {{ info.last_address }}
>>> >> value="1">
>>> 
>>> {

__str__ and __unicode__ not working!!

2015-05-04 Thread Yann Ashuach
In tutorial number one in django documentations, i have tried and tried 
again, and neither the __str__ or the __unicode__ is working! This has been 
a problem for quite a while now... The file i have attached is the code i 
have written. I have looked on many different sites, and haven't found any 
answers. overtime i try, it just gives "Question object" back out..

Thank you in advanced 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5aaa7258-513f-4df1-ad10-4b2cbf55cbb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to Process Multi Step Forms in Django?

2015-05-04 Thread Ken Nguyen
Hi Bernardo,

Using your hidden method works.  I can see the "hidden" value from Form2 
but how do I use those hidden information in form2 so it can redisplay 
correctly?  First time around, it will use the variable from form1.  The 
second time around it should use the hidden information without the 
variable.  How do I achieve that?

You are correct!  I cannot carry the information to the second method in 
view having it the way it is so I've added the session under the 
cleaned_data of form1 and retrieved it at the beginning of form2.

data = name_formset.cleaned_data
request.session ['location'] = location
request.session ['data'] = data

Step 1:  Form1 - Display First Name, Last Name, and location Input Field
Step 2:  Once user submit the information, render the data to form2 and add 
the checkbox next to it.
Step 3:  User choose to select the overwrite checkbox and then click 
"Confirm".
Step 4:  Form2 in view checked for 'POST' method and process cleaned data 
or return empty form2.  This stage created a "Management Form is Missing 
Error" because of the variables that I used in form1 to create the form2 
template are no longer there.  The {{ checkbox_formset.management_form }} 
is already in the template.

Here you can see that the names are displaying correctly.  By the way, I 
made an error in my original post.  It was supposed to be "last_name" not 
"last_address".




form2.html
form2.html




{% load staticfiles %}

User Information


User Information:

{{ checkbox_formset.management_form }}



First Name
Last Name
Overwrite

{% for info in data %}



{{ info.first_name }}
{{ info.last_name }}


{% endfor %}





Cancel







-- 
You received this message because you are subscribed to the Google 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1ca19690-d44f-48e3-8755-d0530ac7fc03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to Process Multi Step Forms in Django?

2015-05-04 Thread Ken Nguyen
Nevermind what I said on my last post, something is internally wrong with 
my second form.  It can't even render when I hard coded the first_name, 
last_name and the checkboxes.  Still getting Management Form Data is 
Missing.





{% load staticfiles %}

User Information


User Information:


{{ checkbox_formset.management_form }}




First Name
Last Name
Overwrite


John
Doe




John
Smith










Cancel





-- 
You received this message because you are subscribed to the Google 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/37a2f383-72fd-4eb4-ad99-c482b80c5d9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: DRF - Which Authentication to use?

2015-05-04 Thread Filipe Ximenes
This is an interesting question. This question enlights some possibilities:
http://stackoverflow.com/questions/21978658/invalidating-json-web-tokens
But none of then gives is a definitive solution. Does anyone have other
ideas about the subject?
On May 1, 2015 10:13 AM, "Nabeel Valapra"  wrote:

> I have prior experience in Django. Recently I got a project to build in
> REST architecture. I learned the basics of Django Rest Framework. But I am
> stuck with the authentication system.
>
> I planned serve my frontend in anguarjs an host it on app.mydomain.com,
> and the DRF on api.mydomain.com. So all the end application (android,
> IOS) can pull the the data from api.mydomain.com
>
> Here I don't want to use session authentication system, it doesn't play
> nice with CORS. I am more interested on JSONWebToken than Token Based
> Authentication because its signed and allows refresh token option too.
>
> But, 1. How do I invalidate the existing tokens on password change? 2. How
> to destroy the token in a mobile lost scenario?
>
> Is there any better authentication solution?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/fabc7ac3-7343-48dc-8cfe-db909a5d6795%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA-QWB1Bj9gQfv7oCXH_PnZGeS%2B0m-dmfELXG9y0XXUEy2GuoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: __str__ and __unicode__ not working!!

2015-05-04 Thread James Schneider
Python 2 or Python 3?

What code ate you using to print the object? A simple print statement?

-James
On May 4, 2015 3:20 PM, "Yann Ashuach"  wrote:

> In tutorial number one in django documentations, i have tried and tried
> again, and neither the __str__ or the __unicode__ is working! This has been
> a problem for quite a while now... The file i have attached is the code i
> have written. I have looked on many different sites, and haven't found any
> answers. overtime i try, it just gives "Question object" back out..
>
> Thank you in advanced 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5aaa7258-513f-4df1-ad10-4b2cbf55cbb6%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUheHdjRjwrTBVz3_7CV2DTpqUkH8F8XT8QpWtLAogP8w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django 1.8 customize site title

2015-05-04 Thread drakkan
the problem was caused by django-admin-bootstrapped

Il giorno lunedì 4 maggio 2015 18:46:08 UTC+2, André Luiz ha scritto:
>
> You can do it in in urls.py for example[1]
>
> [1]: https://gist.github.com/dvl/0bed149bee4556b32d7a
>
> 2015-05-02 5:55 GMT-03:00 drakkan >:
>
>> Hi,
>>
>> I would like to customize django 1.8 site title without override the 
>>  template using AdminSite,
>>
>> I customized AdminSite as per doc here:
>>
>>
>> https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#customizing-the-adminsite-class
>>
>> this seems to work, however the html title still has "Django 
>> administration", 
>>
>> I added site_header and site_title to AdminSite, is this a bug or am I 
>> doing something wrong?
>>
>> here is the html
>>
>> Django administration | MyCustomTitle
>> 
>>
>>
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/6668d66c-4235-47a0-933c-0a81e50142b2%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/09296221-49f1-4082-8f7d-ca5e22502fab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.