filter from databse list

2013-10-29 Thread Mahantesh U
Hi,

   I'm using chcekboxes for 3 location india,china,usa in my form. The 
selected filed are stoiring in database in list like:  location: 
['india','china', 'usa']


1st row in databse:  ['india']
2nd row in databse:  ['india', 'china']
3rd row in databse:  ['india', 'china', 'usa']


in my views.py file:
 
  faculty_list = serializers.serialize("json", 
camp_faculty.objects.all().filter(location=location_param))

  By calling API:
 
HTTP://localhost:8000/fetchform/

   The above API returning only data where location=india

  But If i pass location_param='india' I want all the all the three rows 
from database. How can i achieve this?

 Pls let me know the solution.


Thanks
mahantesh




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/f738edb9-db4a-44c8-8e04-ec53d7b72ee7%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: setting csrftoken to httponly and building ajax forms: not going to happen?

2013-10-29 Thread Tom Evans
On Sat, Oct 26, 2013 at 11:18 PM, Spork Spork  wrote:
> Hi,
>
> I'm using Django 1.4.1b, and for security purposes would like to make the
> csrftoken cookie httponly, and therefore inaccessible from Javascript. Since
> this support is not available in my version of Django, I planned to follow
> this implementation approach:
> http://stackoverflow.com/questions/10861784/django-csrf-cookie-httponly.
>
> But I also build AJAX requests, where I use the suggested approach outlined
> in the Django docs
> (https://docs.djangoproject.com/en/1.4/ref/contrib/csrf/#ajax), which
> involves getting the cookie and setting the x-csrftoken header in
> Javascript.
>
> It looks to me like these two goals are fundamentally incompatible. Am I
> wrong? Is there some way to have both httponly csrf cookies and AJAX?
>
> Many thanks!
>
> Spork

Yes, (unsurprisingly) if you force the CSRF cookie to be unreadable
from javascript, then you will not be able to use javascript to
extract the CSRF token from the CSRF cookie when you submit an AJAX
request.

The requirement in order to use CSRF is for your AJAX submission to
include a CSRF token. This means you must insert the token some other
way, eg by including a hidden element in the form or page that
specifies the CSRF token, and will be included when the form is
submitted via AJAX, or extracted from the page and sent with the AJAX
request.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/CAFHbX1%2ByLnExr2VX%3DpgMqdGpdpA6YgK6v9kZFpvv%2BG-mnxcb2Q%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


django-allauth: Multiple signup forms

2013-10-29 Thread Franco Alarcon
Greetings everyone,
  I know that maybe this is not the best place to ask, but I already asked 
in the django-alluth forum without luck, so here I'm.
  I'm developing an application in which exists two kind of user and I have 
to show a different singup form for each one. The first thing that I 
thought was subclass the SignupView and replace the SignupForm with my 
custom form, then in the urls.py create 2 urls where each one points 
towards my custom SingupViews and it's done. Sadly i couldn't be more 
wrong, because when the user is not logged in it is redirected to 
/accounts/login the to the provider, for instance facebook and then back to 
/accounts/signup/ and not to my SignupView. I tried changing the "next" url 
parameter without luck. So anybody knows how i could have two different 
signup forms one for each kind of user?

Thanks in advance ;)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/39b7b97c-84d6-4a50-81b2-523fa0ee5ce6%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Keyword arguments passed to ListView.as_view() in urlconf ignored, django 1.5.4

2013-10-29 Thread Chang Sun
code segment 1:

url(r'^some_url$', SomeTemplateView.as_view(), {'tab': 'index'}),

the 'tab' variable can be fetched in the template
while in 

code segment 2:

url(r'^some_url$', SomeListView.as_view(), {'tab': 'index'}),

the 'tab' variable is missing in the template.

I found that in Lib\site-packages\django\views\generic\list.py 
in line 139 context = 
self.get_context_data(object_list=self.object_list)
the **kwargs are not passed to self.get_context_data

Could this be regarded as a bug of django 1.5.4?

Appreciate any responses!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/e8617db9-1ff2-4b4c-9afe-21ae13334363%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Keyword arguments passed to ListView.as_view() in urlconf ignored, django 1.5.4

2013-10-29 Thread tim
I don't think so. There is actually a ticket to discontinue this behavior 
on the CBVs that do it: https://code.djangoproject.com/ticket/19878

On Tuesday, October 29, 2013 9:51:06 AM UTC-4, Chang Sun wrote:
>
> code segment 1:
>
> url(r'^some_url$', SomeTemplateView.as_view(), {'tab': 'index'}),
>
> the 'tab' variable can be fetched in the template
> while in 
>
> code segment 2:
>
> url(r'^some_url$', SomeListView.as_view(), {'tab': 'index'}),
>
> the 'tab' variable is missing in the template.
>
> I found that in Lib\site-packages\django\views\generic\list.py 
> in line 139 context = 
> self.get_context_data(object_list=self.object_list)
> the **kwargs are not passed to self.get_context_data
>
> Could this be regarded as a bug of django 1.5.4?
>
> Appreciate any responses!
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/edb4b990-9e67-409b-8252-9d606d48120c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Django Transactions Performance increase

2013-10-29 Thread Robin Fordham
Hi,

I have been doing some reading and am looking to increase the performance 
of updating existing database entries via incoming datafeeds.

I am finding conflicting opinions if wrapping updates in a transaction 
context manager helps improve performance, some sources say it does, others 
say it simply provides data integrity across the queryset within the 
transaction and no performance improvements and others have cited the 
transaction management overhead actually degrades performance;

for instance:

with transaction.commit_on_success()
for row in updatedata:
i = item.objects.get(id=row[0])
i.foo = row[1]
i.baa = row[2]
i.save()

for row in updatedata:
i = item.objects.get(id=row[0])
i.foo = row[1]
i.baa = row[2]
i.save()

Some clarification on this matter would be greatly appreciated. Also any 
pointers to improve my updating efficiency would be appreciated (although I 
know I cannot do a filter and a .update() on the queryset, as each row's 
update data is distinct).

Thanks.

Regards,

Robin.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/8dd77008-1715-4c63-9860-d82ce5c65131%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Transactions Performance increase

2013-10-29 Thread Tom Evans
On Tue, Oct 29, 2013 at 2:39 PM, Robin Fordham  wrote:
> Hi,
>
> I have been doing some reading and am looking to increase the performance of
> updating existing database entries via incoming datafeeds.
>
> I am finding conflicting opinions if wrapping updates in a transaction
> context manager helps improve performance, some sources say it does, others
> say it simply provides data integrity across the queryset within the
> transaction and no performance improvements and others have cited the
> transaction management overhead actually degrades performance;
>
> for instance:
>
> with transaction.commit_on_success()
> for row in updatedata:
> i = item.objects.get(id=row[0])
> i.foo = row[1]
> i.baa = row[2]
> i.save()
>
> for row in updatedata:
> i = item.objects.get(id=row[0])
> i.foo = row[1]
> i.baa = row[2]
> i.save()
>
> Some clarification on this matter would be greatly appreciated. Also any
> pointers to improve my updating efficiency would be appreciated (although I
> know I cannot do a filter and a .update() on the queryset, as each row's
> update data is distinct).
>

This is inefficient. Each row you are updating requires 2 queries, one
to fetch the existing row, one to update it.

for row in updatedata:
   Item.objects.filter(id=row[0]).update(foo=row[1], baa=row[2])

This variant would execute only one query per row, and is entirely
atomic even without transactions, since the fetch/update/store happens
entirely in the database (although the entire update operation is not
atomic, to do that would require a transaction).

As to speed, adding transactions does have some cost, test it and see.
The variant I wrote above is extremely unlikely to ever throw an
exception however - if the database server disappears or crashes, or
the table doesn't have the columns indicated, that could cause an
exception.

Since commit_on_success only doesn't commit when an exception is
raised, it means there is highly unlikely to ever be an exception
worth rolling back. If the DB server crashes or goes away, you are
going to find it difficult to roll back the transaction (!), if the
columns aren't there it will fail on the first query, and nothing will
have changed and so there is nothing to roll back.

If you cannot update the database without first creating the model
instance - perhaps you need to call a method on the model instance in
order to get one of the values to update, for example - then you could
still speed it up slightly by reducing the number of queries to load
model data, by loading the model instances in bulk.

There is a limit of how many objects you would want to create in one
go, normally by the length of the query you are allowed to send to the
database server, so you might require some logic to work out the batch
to load from your long list of ids. Eg, you probably cannot load a
million objects at a time, but you can load 10,000 at a time no
bother, so instead of a million queries to look up items, you have
100.

The DB server still does much the same work, so you are saving
(100 - 100) * query_overhead.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/CAFHbX1KMDtQrS6rAMwfVBUfK9%3D01gyHYJrfUrYi6Q%2Bo0FuwvWA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Digging up Django class-based views - 1

2013-10-29 Thread Tom Evans
On Mon, Oct 28, 2013 at 8:01 AM, Leonardo Giordani
 wrote:
> Hi all,
>
> I want to share with you a post about class-based views.
> Hope you find it useful.
>
> http://lgiordani.github.io/blog/2013/10/28/digging-up-django-class-based-views-1/
>

Nice - clearly written. You have a couple of typos in your code blocks
in the "URL Dispatchers and views" section, **kwds instead of **kwargs
as in the method definition.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/CAFHbX1JCVyoocEqreOeOSWzxZUiY3e7Xb4WEQr0VBr_SgLg5Ew%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Digging up Django class-based views - 1

2013-10-29 Thread Leonardo Giordani
Thank you! I am going to correct it asap.

Leonardo Giordani
Author of The Digital Cat 
My profile on About.me  - My GitHub
page- My Coderwall
profile 


2013/10/29 Tom Evans 

> On Mon, Oct 28, 2013 at 8:01 AM, Leonardo Giordani
>  wrote:
> > Hi all,
> >
> > I want to share with you a post about class-based views.
> > Hope you find it useful.
> >
> >
> http://lgiordani.github.io/blog/2013/10/28/digging-up-django-class-based-views-1/
> >
>
> Nice - clearly written. You have a couple of typos in your code blocks
> in the "URL Dispatchers and views" section, **kwds instead of **kwargs
> as in the method definition.
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send 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/CAFHbX1JCVyoocEqreOeOSWzxZUiY3e7Xb4WEQr0VBr_SgLg5Ew%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/CAEhE%2BOkwmodjrysxrj-t-jo8s6%2BnV4Rvgve_7ObttN54GkEM%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Transactions Performance increase

2013-10-29 Thread Robin Fordham
Thanks Tom, that clears things up a lot and gives me something to work on.

Sorry for the noob question;

If you cannot update the database without first creating the model
> instance - perhaps you need to call a method on the model instance in
> order to get one of the values to update, for example - then you could
> still speed it up slightly by reducing the number of queries to load
> model data, by loading the model instances in bulk.
>

What do you mean by this?

By the nature of the data coming in it is pre validated, so I know already
that row[0] is a valid id, row[1] is a valid foo value, row[2] is a valid
baa value.

Thanks.

Robin.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/CADAnijZ1jdHOdTwzq0B45w3SAFC9Wqp2V0A_S4NcUNW5CU7YVA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django ManyToMany performance?

2013-10-29 Thread Tom Evans
On Mon, Oct 28, 2013 at 8:23 PM, Ruturaj Dhekane  wrote:
> Thanks Daniel and Robin.
>
> Have we seen the scales where Many-to-many DBs through Django work well?
> Like 50K articles in 5K publications.

Numbers are really meaningless. One of our legacy products has a
database with 300 million rows in it, it works as well in Django as it
does in C++, because what the application connecting to the database
"is" is largely irrelevant, what matters is what it does to the
database.

> The aim of this question was to make a design choice too - whether I should
> use Django constructs/calls directly or should i write my own SQL to make
> queries - as my schemas are not just many-to-many but a lot more than that.
>
> Thanks for the suggestion on getting the DB schemas reviewed by a DB expert.
> I realized that is going to help me a lot for sure!

Almost anything you can express in a RDBMS DDL can be encapsulated as
a django model - probably the only major outstanding issue is multi
column primary keys. Using django or using direct SQL on the same
schema will produce identical results.

Besides which, django does not restrict you from using SQL, which is
sometimes necessary - whilst django covers most of SQL as DDL, there
are many many DML SQL queries that you cannot express in django's ORM.

(DDL = Data Definition Language, DML = Data Manipulation Language, in
case any of those terms are unclear)

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/CAFHbX1Lr9CMCgoLrfHS%3DX-WKrbEOMa0640nWwNi_yJ5E_iMkRw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Transactions Performance increase

2013-10-29 Thread Apostolos Bessas
Hi Robin,

As far as I can tell, using one transaction should increase the
performance of the process. The reason is that you issue just one
COMMIT for the whole process instead of one per UPDATE. As an added
benefit, it helps with the data integrity.

There are two main ways I know you can improve the performance:
- Use executemany
(http://initd.org/psycopg/docs/cursor.html#cursor.executemany), which
issues O(n) queries, but does the query planning only once. One app
that uses executemany is django-bulk:
https://github.com/KMahoney/django-bulk and
https://github.com/transifex/django-bulk for some updated code.
- or use COPY (for postgresql), which uses three queries, but has
other kinds of overhead. I guess that other RDBMSs provide a similar
functionality.

The COPY method is the following: You create a new table (probably a
temporary one), COPY all entries there and then do an update in one
query. You can find an implementation of COPY for django in
https://github.com/mpessas/django-pg-extensions/blob/master/djangopg/copy.py
(that's mine).

Which one is preferrable depends on the number of queries you have.

Hope this helps a bit,
Apostolis

On Tue, Oct 29, 2013 at 4:39 PM, Robin Fordham  wrote:
> Hi,
>
> I have been doing some reading and am looking to increase the performance of
> updating existing database entries via incoming datafeeds.
>
> I am finding conflicting opinions if wrapping updates in a transaction
> context manager helps improve performance, some sources say it does, others
> say it simply provides data integrity across the queryset within the
> transaction and no performance improvements and others have cited the
> transaction management overhead actually degrades performance;
>
> for instance:
>
> with transaction.commit_on_success()
> for row in updatedata:
> i = item.objects.get(id=row[0])
> i.foo = row[1]
> i.baa = row[2]
> i.save()
>
> for row in updatedata:
> i = item.objects.get(id=row[0])
> i.foo = row[1]
> i.baa = row[2]
> i.save()
>
> Some clarification on this matter would be greatly appreciated. Also any
> pointers to improve my updating efficiency would be appreciated (although I
> know I cannot do a filter and a .update() on the queryset, as each row's
> update data is distinct).
>
> Thanks.
>
> Regards,
>
> Robin.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send 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/8dd77008-1715-4c63-9860-d82ce5c65131%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/CAEa3b%2BorXwyc4H_7C6T2Ppb2EE_wNQFKgCSsL2y37iP%2BQo24rw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Transactions Performance increase

2013-10-29 Thread Tom Evans
On Tue, Oct 29, 2013 at 4:29 PM, Robin Fordham  wrote:
> What do you mean by this?
>
> By the nature of the data coming in it is pre validated, so I know already
> that row[0] is a valid id, row[1] is a valid foo value, row[2] is a valid
> baa value.
>

In case you were simplifying the example for the list, and what you
actually needed to do was this:

for row in updatedata:
  obj = Object.objects.get(id=row[0])
  obj.foo = run_some_calculation(obj, row[1])
  obj.baa = row[2]
  obj.save()

eg, so you required the object itself. If that was the case, you would
still get benefit from loading multiple objects at once, since you
would issue less queries. However, to do so would require some magic
in order to chunk updatadata into sets small enough to load all at
once, ~10,000 objects at a time. (magic ommitted :)

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/CAFHbX1JuWz9GBU3ezSp737Ywa-6zK_DafYva6jbiR82BiQy1ww%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Digging up Django class-based views - 1

2013-10-29 Thread pywebdesign
thank you so much! this is amazing and respond exactly to what I was trying 
to understand!

On Monday, 28 October 2013 04:01:47 UTC-4, Leo wrote:
>
> Hi all,
>
> I want to share with you a post about class-based views.
> Hope you find it useful.
>
>
> http://lgiordani.github.io/blog/2013/10/28/digging-up-django-class-based-views-1/
>
>
> Leonardo Giordani
> Author of The Digital Cat 
> My profile on About.me  - My GitHub 
> page  - My Coderwall 
> profile
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/f09e04cb-5bfb-4d2f-9a4e-4f267e59f992%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: django difference between - one to one, many to one and many to many

2013-10-29 Thread Aamu Padi
Thank you so much! I will look into that! :)

On Tuesday, October 29, 2013 1:37:37 AM UTC+5:30, C. Kirby wrote:
>
> Those concepts are actually RDBMS (Database) ideas. You would probably be 
> better off reading up on those. This looks to be a pretty good explanation:
>
> http://net.tutsplus.com/tutorials/databases/sql-for-beginners-part-3-database-relationships/
>
>
> On Monday, October 28, 2013 2:06:20 PM UTC-5, Aamu Padi wrote:
>>
>> So, this is my first time learning computer language. And I chose python 
>> and django. Now, I got many of the basic concepts of python and also 
>> django. I can create new page with the views and all other stuff. But I am 
>> still confused with the relations, i.e. one to one, many to one, and many 
>> to many. Will someone please please please explain it to me. How can I use 
>> it? I really need to know.
>>
>> *N.B:* I have looked at this 
>> linkfor
>>  that, but 
>> I still have some doubts about one-to-one and many-to-many. Suppose I 
>> want to extend with some more user information in a different class. Can I 
>> use ForeignKey instead of One-to-One field? And will anyone please be 
>> kind enough to explain to me about many-to-many relationship, (I didn't 
>> quit understood all those toppings and membership thing). 
>>
>> 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/859a5ba6-34d1-4994-9e55-1ceb81549a50%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: django difference between - one to one, many to one and many to many

2013-10-29 Thread Sandeep kaur
On Tue, Oct 29, 2013 at 12:36 AM, Aamu Padi  wrote:
>
> So, this is my first time learning computer language. And I chose python
and django. Now, I got many of the basic concepts of python and also
django. I can create new page with the views and all other stuff. But I am
still confused with the relations, i.e. one to one, many to one, and many
to many. Will someone please please please explain it to me. How can I use
it? I really need to know

many to one :
This relationship is used as foreign key. In this one table can be used as
a parent for many children.
Eg :

class Manufacturer(models.Model):
# ...
pass

class Car(models.Model):
manufacturer = models.ForeignKey('Manufacturer')
# ...

class Bus(models.Model):
manufacturer = models.ForeignKey('Manufacturer')
# ...

Here there is one base table Manufacturer which acts as base for 2 other
tables.

many to many :
When you want many rows of a table to be linked to many rows of another
table, we use manytomany field.

class Vehicle(models.Model):
   # ..
   manufacturer = models.ManyToManyField(Manufacturer)
For more :
http://charlesleifer.com/blog/describing-relationships-djangos-manytomany-through/

Application : For making checkboxes

one to one :
This is similar to foreign key, except that one parent has only one child.
Conceptually, this is similar to a ForeignKey with unique=True, but the
“reverse” side of the relation will directly return a single object.

class Car(models.Model):
manufacturer = OneToOneField('Manufacturer')
# ...

Hope this helped.



-- 
Sandeep Kaur
E-Mail: mkaurkha...@gmail.com
Blog: sandymadaan.wordpress.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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF66xG01aUyofi4jTRnpTzvne8Ao2Aiczm8DTEfa_TAUw%2B%3DOSA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


RestFul with Class Based Views best practice

2013-10-29 Thread pywebdesign
Hi,

I am trying to find/develop a best way to name and organize Views class to 
be consistent and flexible.

I am working on a project witch involve an model called Song. It's kind of 
a midi song in a database with attibutes about authors, name ... to make it 
simple.

Now I want web pages that permit to create a new song, edit a song, delete 
it or simply view it.
I also want a list page that list song by authors, by instrument (a typical 
search and return a list). the idea is to make the list editable via ajax. 
people change something on a list and it saves it to the browser when done 
without quitting the list. Very useful to modify many list at the same time.
There is also a page to create/upload 5 song at a time.

I was searching the best structure for my Class Based View. Right now I 
came up with this one:

class SongForm
def get_new_song
def post_new_song

def get_modify_song
def put_song

def get_delete_song
def delete_song

class SongListForm
def get_list_song(search infos)

class SongView
get_Song


ok that's about it. It look wrong, one big class and to very small one. I 
would like some pointer to some best practice to create this kind of CRUD 
as RESTFUL.

Thank you very much


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/61688c29-1d49-4d1a-9d04-45192d00c78d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: RestFul with Class Based Views best practice

2013-10-29 Thread Marc Aymerich
On Tue, Oct 29, 2013 at 8:45 PM, pywebdesign  wrote:

> Hi,
>
> I am trying to find/develop a best way to name and organize Views class to
> be consistent and flexible.
>
> I am working on a project witch involve an model called Song. It's kind of
> a midi song in a database with attibutes about authors, name ... to make it
> simple.
>
> Now I want web pages that permit to create a new song, edit a song, delete
> it or simply view it.
> I also want a list page that list song by authors, by instrument (a
> typical search and return a list). the idea is to make the list editable
> via ajax. people change something on a list and it saves it to the browser
> when done without quitting the list. Very useful to modify many list at the
> same time.
> There is also a page to create/upload 5 song at a time.
>
> I was searching the best structure for my Class Based View. Right now I
> came up with this one:
>
> class SongForm
> def get_new_song
> def post_new_song
>
> def get_modify_song
> def put_song
>
> def get_delete_song
> def delete_song
>
> class SongListForm
> def get_list_song(search infos)
>
> class SongView
> get_Song
>
>
> ok that's about it. It look wrong, one big class and to very small one. I
> would like some pointer to some best practice to create this kind of CRUD
> as RESTFUL.
>


Hi, what i'd do if I want to be restful is create two views, one for
listing and creating songs and another for reading, updating and deleting
existing songs

class SongList
   # url /songs/
   def get: list songs
   def post: create new song

class Song
   # url /songs/
   def get
   def put
   def patch
   def delete

I think with these two views you can cover all use-cases you've described :)

-- 
Marc

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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%2BDCN_utdjJ39dY7kgE4-Nx7WXRpfVpe-Lo2V4CZsoUcJrn-SA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: RestFul with Class Based Views best practice

2013-10-29 Thread Xavier Ordoquy
Hi,

You probably want to have a look at django rest framework.
You use can will be easy with it, in particular if you use 
http://django-rest-framework.org/api-guide/viewsets.html#modelviewset

Regards,
Xavier.

Le 29 oct. 2013 à 20:45, pywebdesign  a écrit :

> Hi,
> 
> I am trying to find/develop a best way to name and organize Views class to be 
> consistent and flexible.
> 
> I am working on a project witch involve an model called Song. It's kind of a 
> midi song in a database with attibutes about authors, name ... to make it 
> simple.
> 
> Now I want web pages that permit to create a new song, edit a song, delete it 
> or simply view it.
> I also want a list page that list song by authors, by instrument (a typical 
> search and return a list). the idea is to make the list editable via ajax. 
> people change something on a list and it saves it to the browser when done 
> without quitting the list. Very useful to modify many list at the same time.
> There is also a page to create/upload 5 song at a time.
> 
> I was searching the best structure for my Class Based View. Right now I came 
> up with this one:
> 
> class SongForm
> def get_new_song
> def post_new_song
> 
> def get_modify_song
> def put_song
> 
> def get_delete_song
> def delete_song
> 
> class SongListForm
> def get_list_song(search infos)
> 
> class SongView
> get_Song
> 
> 
> ok that's about it. It look wrong, one big class and to very small one. I 
> would like some pointer to some best practice to create this kind of CRUD as 
> RESTFUL.
> 
> Thank you very much
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send 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/61688c29-1d49-4d1a-9d04-45192d00c78d%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/27DD4867-A47A-4E9F-8417-1DF2D6F1E742%40linovia.com.
For more options, visit https://groups.google.com/groups/opt_out.


multiple databases and syncdb problem

2013-10-29 Thread Sells, Fred
I can syncdb OK if I don't add allow_syncdb to my router, but if I add the 
allow_syncdb to the router, only my default db is synced.  Any idea what I'm 
doing wrong, code is:

def allow_syncdb(self, db, model):
print 'allow syncdb for* Inserv Router', db, 
model._meta.app_label
return db=='inserv' and model._meta.app_label == 'inserv'

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/DCD75728F460F14586086EA606E83082E71DE597%40ACEVXCHMBX1001.ADVENTISTCORP.NET.
For more options, visit https://groups.google.com/groups/opt_out.


Re: multiple databases and syncdb problem

2013-10-29 Thread Simon Charette
syncdb defaults to syncing the 'default' database when no --database is 
specified
.

Try specifying which database to synchronize, with the --database=inserv 
flag in your case.

Le mardi 29 octobre 2013 16:52:15 UTC-4, fred a écrit :
>
>  I can syncdb OK if I don’t add allow_syncdb to my router, but if I add 
> the allow_syncdb to the router, only my default db is synced.  Any idea 
> what I’m doing wrong, code is:
>
>  
>
> def *allow_syncdb*(*self*, db, model):
>
> print *'allow syncdb for* Inserv Router'*, db, 
> model._meta.app_label
>
> return db==*'inserv'* and model._meta.app_label == *'inserv'*
>
>  
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/48432761-428b-4e17-80d6-05f6c01de318%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: RestFul with Class Based Views best practice

2013-10-29 Thread pywebdesign
Ok, thank you! I was not doing it correctly at all. 
http://django-rest-framework.org is amazing.

I am now using Marc's design and trying to event use CreateView and other 
generic view

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/0709023c-dc52-4fb2-bcb6-9474e99ee24c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: django-stdimage NoneType problem

2013-10-29 Thread Russell Keith-Magee
Hi Oscar,

The error you describe is the sort of thing that happens when a comma goes
missing, particularly in a list of tuples, but it's possible in other
circumstances, too.

Take the following code as an example:

x = [
  None
  (4, 5, 6)
]

On first inspection, this looks fine -- a list that contains a None and a
 tuple. But then you notice that there's no comma after the None -- so what
you're asking Python to do is to invoke None as a function, using (4,5,6)
as arguments. This causes a "NoneType object is not callable" error.

In your case, the problem isn't manifesting at the raw syntactic level. I'm
not entirely sure how the setattr call you describe could be used to
generate this error, however.

Unfortunately, its difficult to provide any more advice beyond this without
knowing more about your code. The error is being raised in your own code
space, so it isn't strictly a problem that Django itself is causing -- at
best, it's an interaction between your code's expectations and what Django
is actually returning. If you're depending on some internal value in
Django's meta classes, and that value changed between 1.5.5 and 1.6rc1,
then it's possible you might start getting errors.

I wouldn't read too much into where ipdb stops -- if you look at the stack,
it's stopped at the first frame in your own code (2 frames up from where
./manage.py dumped stack).

Yours,
Russ Magee %-)


On Mon, Oct 28, 2013 at 4:31 PM, Oscar Carballal  wrote:

> Hi,
>
> I'm starting to port my project (e-cidadania) into python 3 and django
> 1.6rc1, but I'm currently facing a problem that I can't understand.
>
> When I try to do a runserver or a syncdb or any other command, it breaks
> with this message:
>
> ➜  src git:(python3) ✗ ./manage.py syncdb
> TypeError: 'NoneType' object is not callable
>
> This is the full traceback:
>
> ➜  src git:(python3) ✗ ./manage.py syncdb --traceback
> Traceback (most recent call last):
>   File "/usr/lib/python3.3/site-packages/django/core/management/base.py",
> line 222, in run_from_argv
> self.execute(*args, **options.__dict__)
>   File "/usr/lib/python3.3/site-packages/django/core/management/base.py",
> line 254, in execute
> self.validate()
>   File "/usr/lib/python3.3/site-packages/django/core/management/base.py",
> line 280, in validate
> num_errors = get_validation_errors(s, app)
>   File
> "/usr/lib/python3.3/site-packages/django/core/management/validation.py",
> line 35, in get_validation_errors
> for (app_name, error) in get_app_errors().items():
>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
> line 166, in get_app_errors
> self._populate()
>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
> line 72, in _populate
> self.load_app(app_name, True)
>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
> line 96, in load_app
> models = import_module('.models', app_name)
>   File "/usr/lib/python3.3/site-packages/django/utils/importlib.py", line
> 35, in import_module
> __import__(name)
>   File "/usr/lib/python3.3/site-packages/guardian/models.py", line 89, in
> 
> User = get_user_model()
>   File "/usr/lib/python3.3/site-packages/django/contrib/auth/__init__.py",
> line 127, in get_user_model
> user_model = get_model(app_label, model_name)
>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
> line 230, in get_model
> self._populate()
>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
> line 72, in _populate
> self.load_app(app_name, True)
>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
> line 96, in load_app
> models = import_module('.models', app_name)
>   File "/usr/lib/python3.3/site-packages/django/utils/importlib.py", line
> 35, in import_module
> __import__(name)
>   File
> "/home/oscarcp/devel/cidadania/ecidadania/src/core/spaces/models.py", line
> 31, in 
> class Space(models.Model):
>   File
> "/home/oscarcp/devel/cidadania/ecidadania/src/core/spaces/models.py", line
> 56, in Space
> blank=True, null=True)
>   File
> "/home/oscarcp/devel/cidadania/ecidadania/src/core/spaces/fields.py", line
> 129, in __init__
> setattr(self, att_name, dict(map(None, params_size, att)))
> TypeError: 'NoneType' object is not callable
>
>
> I though it might be a problem from django-stdimage, but doing an ipdb
> over the affected code returned this:
>
> ipdb> n
> TypeError: 'NoneType' object is not callable
> >
> /home/oscarcp/devel/cidadania/ecidadania/src/core/spaces/models.py(31)()
>  30
> ---> 31 class Space(models.Model):
>  32
>
> Anyone has a clue of where could be the problem? The code runs just fine
> with python 2.7.5 and django 1.5.5
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post t

Re: django.utils.copycompat is deprecated

2013-10-29 Thread Russell Keith-Magee
Hi Tino

On Tue, Oct 29, 2013 at 12:49 AM, tino  wrote:

> Hello,
>
> I am getting the following in apache error log.
>
>
> [error]
> /home/findme/virtualenv/lib/python2.7/site-packages/django/utils/copycompat.py:10:
> DeprecationWarning: django.utils.copycompat is deprecated; use the native
> copy module instead
>
>
Well, it's only an issue if you're expecting your code to keep running into
the future :-)

It will become an issue when you upgrade to the next version of Django (the
version one release above what you're currently using). At that point, your
code will stop working because you'll be trying to import a module that no
longer exists. Django's deprecation process involves introducing warnings
like the one you've reported so that you are informed that your code is
using a deprecated feature.

Keep in mind that it might not be your own code that is importing
copycompat -- it might be a third party library. In that case, the third
party library will need to be updated.

The only thing I can guarantee is that it *isn't* being caused by Django
itself.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/CAJxq8489BVjLiuoDMFrgQVEnpzTwsYKoyGeA9-fiMNM%2BD42VNA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: django-stdimage NoneType problem

2013-10-29 Thread Oscar Carballal
Thanks Russell, I actually see a comma after the None... I'm not sure what
you're referring to.

Well, it's an opensource project, so here you go :)
https://github.com/cidadania/e-cidadania

The affected code is located here (both fields.py and models.py)
https://github.com/cidadania/e-cidadania/tree/master/src/core/spaces

Actually you're right, but even then ipdb doesn't show a very helpful
output. I'm putting it in a pastebin to avoid cluttering the mail:
https://dpaste.de/asTw


2013/10/30 Russell Keith-Magee 

> Hi Oscar,
>
> The error you describe is the sort of thing that happens when a comma goes
> missing, particularly in a list of tuples, but it's possible in other
> circumstances, too.
>
> Take the following code as an example:
>
> x = [
>   None
>   (4, 5, 6)
> ]
>
> On first inspection, this looks fine -- a list that contains a None and a
>  tuple. But then you notice that there's no comma after the None -- so what
> you're asking Python to do is to invoke None as a function, using (4,5,6)
> as arguments. This causes a "NoneType object is not callable" error.
>
> In your case, the problem isn't manifesting at the raw syntactic level.
> I'm not entirely sure how the setattr call you describe could be used to
> generate this error, however.
>
> Unfortunately, its difficult to provide any more advice beyond this
> without knowing more about your code. The error is being raised in your own
> code space, so it isn't strictly a problem that Django itself is causing --
> at best, it's an interaction between your code's expectations and what
> Django is actually returning. If you're depending on some internal value in
> Django's meta classes, and that value changed between 1.5.5 and 1.6rc1,
> then it's possible you might start getting errors.
>
> I wouldn't read too much into where ipdb stops -- if you look at the
> stack, it's stopped at the first frame in your own code (2 frames up from
> where ./manage.py dumped stack).
>
> Yours,
> Russ Magee %-)
>
>
> On Mon, Oct 28, 2013 at 4:31 PM, Oscar Carballal  wrote:
>
>> Hi,
>>
>> I'm starting to port my project (e-cidadania) into python 3 and django
>> 1.6rc1, but I'm currently facing a problem that I can't understand.
>>
>> When I try to do a runserver or a syncdb or any other command, it breaks
>> with this message:
>>
>> ➜  src git:(python3) ✗ ./manage.py syncdb
>> TypeError: 'NoneType' object is not callable
>>
>> This is the full traceback:
>>
>> ➜  src git:(python3) ✗ ./manage.py syncdb --traceback
>> Traceback (most recent call last):
>>   File "/usr/lib/python3.3/site-packages/django/core/management/base.py",
>> line 222, in run_from_argv
>> self.execute(*args, **options.__dict__)
>>File
>> "/usr/lib/python3.3/site-packages/django/core/management/base.py", line
>> 254, in execute
>> self.validate()
>>   File "/usr/lib/python3.3/site-packages/django/core/management/base.py",
>> line 280, in validate
>> num_errors = get_validation_errors(s, app)
>>   File
>> "/usr/lib/python3.3/site-packages/django/core/management/validation.py",
>> line 35, in get_validation_errors
>> for (app_name, error) in get_app_errors().items():
>>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
>> line 166, in get_app_errors
>> self._populate()
>>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
>> line 72, in _populate
>> self.load_app(app_name, True)
>>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
>> line 96, in load_app
>> models = import_module('.models', app_name)
>>   File "/usr/lib/python3.3/site-packages/django/utils/importlib.py", line
>> 35, in import_module
>> __import__(name)
>>   File "/usr/lib/python3.3/site-packages/guardian/models.py", line 89, in
>> 
>> User = get_user_model()
>>   File
>> "/usr/lib/python3.3/site-packages/django/contrib/auth/__init__.py", line
>> 127, in get_user_model
>> user_model = get_model(app_label, model_name)
>>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
>> line 230, in get_model
>> self._populate()
>>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
>> line 72, in _populate
>> self.load_app(app_name, True)
>>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
>> line 96, in load_app
>> models = import_module('.models', app_name)
>>   File "/usr/lib/python3.3/site-packages/django/utils/importlib.py", line
>> 35, in import_module
>> __import__(name)
>>   File
>> "/home/oscarcp/devel/cidadania/ecidadania/src/core/spaces/models.py", line
>> 31, in 
>> class Space(models.Model):
>>   File
>> "/home/oscarcp/devel/cidadania/ecidadania/src/core/spaces/models.py", line
>> 56, in Space
>> blank=True, null=True)
>>   File
>> "/home/oscarcp/devel/cidadania/ecidadania/src/core/spaces/fields.py", line
>> 129, in __init__
>> setattr(self, att_name, dict(map(None, params_size, att)))
>> TypeError: 'NoneType' object is not callable
>>
>>

Re: django-stdimage NoneType problem

2013-10-29 Thread Oscar Carballal
Oops, sorry Russell, the affected code is here (branch mistake):
https://github.com/cidadania/e-cidadania/blob/python3/src/core/spaces/models.py


2013/10/30 Oscar Carballal 

> Thanks Russell, I actually see a comma after the None... I'm not sure what
> you're referring to.
>
> Well, it's an opensource project, so here you go :)
> https://github.com/cidadania/e-cidadania
>
> The affected code is located here (both fields.py and models.py)
> https://github.com/cidadania/e-cidadania/tree/master/src/core/spaces
>
> Actually you're right, but even then ipdb doesn't show a very helpful
> output. I'm putting it in a pastebin to avoid cluttering the mail:
> https://dpaste.de/asTw
>
>
> 2013/10/30 Russell Keith-Magee 
>
>> Hi Oscar,
>>
>> The error you describe is the sort of thing that happens when a comma
>> goes missing, particularly in a list of tuples, but it's possible in other
>> circumstances, too.
>>
>> Take the following code as an example:
>>
>> x = [
>>   None
>>   (4, 5, 6)
>> ]
>>
>> On first inspection, this looks fine -- a list that contains a None and a
>>  tuple. But then you notice that there's no comma after the None -- so what
>> you're asking Python to do is to invoke None as a function, using (4,5,6)
>> as arguments. This causes a "NoneType object is not callable" error.
>>
>> In your case, the problem isn't manifesting at the raw syntactic level.
>> I'm not entirely sure how the setattr call you describe could be used to
>> generate this error, however.
>>
>> Unfortunately, its difficult to provide any more advice beyond this
>> without knowing more about your code. The error is being raised in your own
>> code space, so it isn't strictly a problem that Django itself is causing --
>> at best, it's an interaction between your code's expectations and what
>> Django is actually returning. If you're depending on some internal value in
>> Django's meta classes, and that value changed between 1.5.5 and 1.6rc1,
>> then it's possible you might start getting errors.
>>
>> I wouldn't read too much into where ipdb stops -- if you look at the
>> stack, it's stopped at the first frame in your own code (2 frames up from
>> where ./manage.py dumped stack).
>>
>> Yours,
>> Russ Magee %-)
>>
>>
>> On Mon, Oct 28, 2013 at 4:31 PM, Oscar Carballal wrote:
>>
>>> Hi,
>>>
>>> I'm starting to port my project (e-cidadania) into python 3 and django
>>> 1.6rc1, but I'm currently facing a problem that I can't understand.
>>>
>>> When I try to do a runserver or a syncdb or any other command, it breaks
>>> with this message:
>>>
>>> ➜  src git:(python3) ✗ ./manage.py syncdb
>>> TypeError: 'NoneType' object is not callable
>>>
>>> This is the full traceback:
>>>
>>> ➜  src git:(python3) ✗ ./manage.py syncdb --traceback
>>> Traceback (most recent call last):
>>>   File
>>> "/usr/lib/python3.3/site-packages/django/core/management/base.py", line
>>> 222, in run_from_argv
>>> self.execute(*args, **options.__dict__)
>>>File
>>> "/usr/lib/python3.3/site-packages/django/core/management/base.py", line
>>> 254, in execute
>>> self.validate()
>>>   File
>>> "/usr/lib/python3.3/site-packages/django/core/management/base.py", line
>>> 280, in validate
>>> num_errors = get_validation_errors(s, app)
>>>   File
>>> "/usr/lib/python3.3/site-packages/django/core/management/validation.py",
>>> line 35, in get_validation_errors
>>> for (app_name, error) in get_app_errors().items():
>>>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
>>> line 166, in get_app_errors
>>> self._populate()
>>>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
>>> line 72, in _populate
>>> self.load_app(app_name, True)
>>>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
>>> line 96, in load_app
>>> models = import_module('.models', app_name)
>>>   File "/usr/lib/python3.3/site-packages/django/utils/importlib.py",
>>> line 35, in import_module
>>> __import__(name)
>>>   File "/usr/lib/python3.3/site-packages/guardian/models.py", line 89,
>>> in 
>>> User = get_user_model()
>>>   File
>>> "/usr/lib/python3.3/site-packages/django/contrib/auth/__init__.py", line
>>> 127, in get_user_model
>>> user_model = get_model(app_label, model_name)
>>>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
>>> line 230, in get_model
>>> self._populate()
>>>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
>>> line 72, in _populate
>>> self.load_app(app_name, True)
>>>   File "/usr/lib/python3.3/site-packages/django/db/models/loading.py",
>>> line 96, in load_app
>>> models = import_module('.models', app_name)
>>>   File "/usr/lib/python3.3/site-packages/django/utils/importlib.py",
>>> line 35, in import_module
>>> __import__(name)
>>>   File
>>> "/home/oscarcp/devel/cidadania/ecidadania/src/core/spaces/models.py", line
>>> 31, in 
>>> class Space(models.Model):
>>>   File
>>> "/home/oscarcp/devel/cidadania/eci

Re: Keyword arguments passed to ListView.as_view() in urlconf ignored, django 1.5.4

2013-10-29 Thread Chang Sun
Thank you for your reply, Tim.

This behavior confuses new users of CBVs. It takes time to learn it.


On Tue, Oct 29, 2013 at 10:30 PM, tim  wrote:

> I don't think so. There is actually a ticket to discontinue this behavior
> on the CBVs that do it: https://code.djangoproject.com/ticket/19878
>
> On Tuesday, October 29, 2013 9:51:06 AM UTC-4, Chang Sun wrote:
>>
>> code segment 1:
>>
>> url(r'^some_url$', SomeTemplateView.as_view(), {'tab': 'index'}),
>>
>> the 'tab' variable can be fetched in the template
>> while in
>>
>> code segment 2:
>>
>> url(r'^some_url$', SomeListView.as_view(), {'tab': 'index'}),
>>
>> the 'tab' variable is missing in the template.
>>
>> I found that in Lib\site-packages\django\**views\generic\list.py
>> in line 139 context = self.get_context_data(object_**
>> list=self.object_list)
>> the **kwargs are not passed to self.get_context_data
>>
>> Could this be regarded as a bug of django 1.5.4?
>>
>> Appreciate any responses!
>>
>  --
> 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/kC46bU-R-6k/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/edb4b990-9e67-409b-8252-9d606d48120c%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 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/CAFEq18GXFGkPA-mj-8FNaBJQoF1SF%2B_qN7-%2BX0u2Ki7ce7DO6A%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.