AW: AW: Performance

2011-12-05 Thread Szabo, Patrick (LNG-VIE)
Okay it seems that specifying which Foreign-Keys it should follow solves
the problem. 

Is this a known issue and can I be sure that this won't cause any
further trouble !?

 

Von: django-users@googlegroups.com
[mailto:django-users@googlegroups.com] Im Auftrag von Szabo, Patrick
(LNG-VIE)
Gesendet: Dienstag, 06. Dezember 2011 08:29
An: django-users@googlegroups.com
Betreff: AW: AW: Performance

 

Thank you, i could cut my queries in half which brings almost a second J

Unfortunately the function seems to effect the results.

 

If I run the query with select_related() I get 151 objects. 

Without select_related() I get 199. 

 

Is there something I can to to overcome this ?!

 

Von: django-users@googlegroups.com
[mailto:django-users@googlegroups.com] Im Auftrag von Felipe Morales
Gesendet: Montag, 05. Dezember 2011 17:50
An: django-users@googlegroups.com
Betreff: Re: AW: Performance

 

Patrick, 

 

try to use select_related() method instead of only filter() when you get
a list of elements, e.g. :

 

queryset = Model.objects.filter().select_related()

 

by this way you'll get only one query instead 800

 

good luck!

 

Felipe

2011/12/5 Nikolas Stevenson-Molnar 

It would help to know a little more about your code here. Could you give
some examples?

 

_NIk

 

On Dec 5, 2011, at 3:18 AM, Szabo, Patrick (LNG-VIE) wrote:

 

Okay that toolbar is really useful and also looks kind of nice
J...Thanks for that.

I've already found the problemsomehow my app triggers 800 queries
just for a simple page.

Can I somehow find out which part of my code is causing those queries ?!

 

patrick

 

 

. . . . . . . . . . . . . . . . . . . . . . . . . .

Ing. Patrick Szabo
XSLT Developer

LexisNexis
Marxergasse 25, 1030 Wien

patrick.sz...@lexisnexis.at

Tel.: 00431 534521573  

Fax: +43 (1) 534 52 - 146  

 

Von: django-users@googlegroups.com
[mailto:django-users@googlegroups.com] Im Auftrag von Nikolas
Stevenson-Molnar
Gesendet: Montag, 05. Dezember 2011 08:14
An: Nikolas Stevenson-Molnar
Cc: django-users@googlegroups.com
Betreff: Re: Performance

 

A bit more searching turned up something even better... looks like the
Django folks address this directly:
https://code.djangoproject.com/wiki/ProfilingDjango

 

_Nik

 

On Dec 4, 2011, at 11:03 PM, Nikolas Stevenson-Molnar wrote:

 

I haven't done this myself, but I would assume you could use the Python
profiler. Here's one project that facilitates profiling a WSGI app
(assuming you're using Django via WSGI): http://repoze.org/

 

Others here may have more experience with profiling web apps.

 

_Nik

 

On Dec 4, 2011, at 10:55 PM, Szabo, Patrick (LNG-VIE) wrote:

 

Hi,

 

In the last couple of weeks my app has become quite slowly and I'm
wondering why that is.

Are there any debugging tools where I can see what takes how much time ?

 

cheers

 

. . . . . . . . . . . . . . . . . . . . . . . . . .

Ing. Patrick Szabo
XSLT Developer

LexisNexis
Marxergasse 25, 1030 Wien

patrick.sz...@lexisnexis.at

Tel.: 00431 534521573  

Fax: +43 (1) 534 52 - 146  

 

 

 

-- 
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.

 

 

-- 
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.

 

 

 

-- 
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.

 

-- 
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
 .
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.





 

-- 
Felipe Morales C.
Ingeniero de Ejecucin en Computacin e Informtica.

-- 
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.

. . . . . . . . . . . . . . . . . . . .

AW: AW: Performance

2011-12-05 Thread Szabo, Patrick (LNG-VIE)
Thank you, i could cut my queries in half which brings almost a second J

Unfortunately the function seems to effect the results.

 

If I run the query with select_related() I get 151 objects. 

Without select_related() I get 199. 

 

Is there something I can to to overcome this ?!

 

Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] Im 
Auftrag von Felipe Morales
Gesendet: Montag, 05. Dezember 2011 17:50
An: django-users@googlegroups.com
Betreff: Re: AW: Performance

 

Patrick, 

 

try to use select_related() method instead of only filter() when you get a list 
of elements, e.g. :

 

queryset = Model.objects.filter().select_related()

 

by this way you'll get only one query instead 800

 

good luck!

 

Felipe

2011/12/5 Nikolas Stevenson-Molnar 

It would help to know a little more about your code here. Could you give some 
examples?

 

_NIk

 

On Dec 5, 2011, at 3:18 AM, Szabo, Patrick (LNG-VIE) wrote:





Okay that toolbar is really useful and also looks kind of nice J...Thanks for 
that.

I've already found the problemsomehow my app triggers 800 queries just for 
a simple page.

Can I somehow find out which part of my code is causing those queries ?!

 

patrick

 

 

. . . . . . . . . . . . . . . . . . . . . . . . . .

Ing. Patrick Szabo
XSLT Developer

LexisNexis
Marxergasse 25, 1030 Wien

patrick.sz...@lexisnexis.at

Tel.: 00431 534521573  

Fax: +43 (1) 534 52 - 146  

 

Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] Im 
Auftrag von Nikolas Stevenson-Molnar
Gesendet: Montag, 05. Dezember 2011 08:14
An: Nikolas Stevenson-Molnar
Cc: django-users@googlegroups.com
Betreff: Re: Performance

 

A bit more searching turned up something even better... looks like the Django 
folks address this directly: https://code.djangoproject.com/wiki/ProfilingDjango

 

_Nik

 

On Dec 4, 2011, at 11:03 PM, Nikolas Stevenson-Molnar wrote:

 

I haven't done this myself, but I would assume you could use the Python 
profiler. Here's one project that facilitates profiling a WSGI app (assuming 
you're using Django via WSGI): http://repoze.org/

 

Others here may have more experience with profiling web apps.

 

_Nik

 

On Dec 4, 2011, at 10:55 PM, Szabo, Patrick (LNG-VIE) wrote:

 

Hi,

 

In the last couple of weeks my app has become quite slowly and I'm wondering 
why that is.

Are there any debugging tools where I can see what takes how much time ?

 

cheers

 

. . . . . . . . . . . . . . . . . . . . . . . . . .

Ing. Patrick Szabo
XSLT Developer

LexisNexis
Marxergasse 25, 1030 Wien

patrick.sz...@lexisnexis.at

Tel.: 00431 534521573  

Fax: +43 (1) 534 52 - 146  

 

 

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

 

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

 

 

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com 
 .
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.





 

-- 
Felipe Morales C.
Ingenierío de Ejecución en Computación e Informática.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


. . . . . . . . . . . . . . . . . . . . . . . . . .
Ing. Patrick Szabo
 XSLT Developer 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick.sz...@lexisnexis.at
Tel.: 00431 534521573 
Fax: +43 (1) 534 52 - 146 





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this

AW: AW: Performance

2011-12-05 Thread Szabo, Patrick (LNG-VIE)
Thank's for the hints...i'll check it out !


. . . . . . . . . . . . . . . . . . . . . . . . . .
Ing. Patrick Szabo
 XSLT Developer 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick.sz...@lexisnexis.at
Tel.: 00431 534521573 
Fax: +43 (1) 534 52 - 146 


-Ursprüngliche Nachricht-

Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] Im 
Auftrag von Tim Sawyer
Gesendet: Montag, 05. Dezember 2011 18:07
An: django-users@googlegroups.com
Betreff: Re: AW: Performance

http://pypi.python.org/pypi/django-debug-toolbar will show the number of
queries, time taken to query, and allow you to see the stack trace for the
code that caused the query to be executed.

Hope that helps,

Tim.

> On Dec 5, 2011, at 3:18 AM, Szabo, Patrick (LNG-VIE) wrote:
>
>> Okay that toolbar is really useful and also looks kind of nice J...Thanks
>> for that.
>> I've already found the problemsomehow my app triggers 800 queries just
>> for a simple page.
>> Can I somehow find out which part of my code is causing those queries ?!
>>
>> patrick
>>
>>
>> . . . . . . . . . . . . . . . . . . . . . . . . . .
>> Ing. Patrick Szabo
>> XSLT Developer
>> LexisNexis
>> Marxergasse 25, 1030 Wien
>>
>> patrick.sz...@lexisnexis.at
>> Tel.: 00431 534521573
>> Fax: +43 (1) 534 52 - 146
>>
>> Von: django-users@googlegroups.com
>> [mailto:django-users@googlegroups.com] Im Auftrag von Nikolas
>> Stevenson-Molnar
>> Gesendet: Montag, 05. Dezember 2011 08:14
>> An: Nikolas Stevenson-Molnar
>> Cc: django-users@googlegroups.com
>> Betreff: Re: Performance
>>
>> A bit more searching turned up something even better... looks like the
>> Django folks address this directly:
>> https://code.djangoproject.com/wiki/ProfilingDjango
>>
>> _Nik
>>
>> On Dec 4, 2011, at 11:03 PM, Nikolas Stevenson-Molnar wrote:
>>
>>
>> I haven't done this myself, but I would assume you could use the Python
>> profiler. Here's one project that facilitates profiling a WSGI app
>> (assuming you're using Django via WSGI): http://repoze.org/
>>
>> Others here may have more experience with profiling web apps.
>>
>> _Nik
>>
>> On Dec 4, 2011, at 10:55 PM, Szabo, Patrick (LNG-VIE) wrote:
>>
>>
>> Hi,
>>
>> In the last couple of weeks my app has become quite slowly and I'm
>> wondering why that is.
>> Are there any debugging tools where I can see what takes how much time ?
>>
>> cheers
>>
>> . . . . . . . . . . . . . . . . . . . . . . . . . .
>> Ing. Patrick Szabo
>> XSLT Developer
>> LexisNexis
>> Marxergasse 25, 1030 Wien
>>
>> patrick.sz...@lexisnexis.at
>> Tel.: 00431 534521573
>> Fax: +43 (1) 534 52 - 146
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Query with no-correspondence results

2011-12-05 Thread wgis
Hey Renout,
thanks for your answer.

But then I would have something like
(Carrots, Flavor,2.0)
as the result

instead of the desired

(Carrots, Flavour, 2.0)
(Carrots, Smell, 0.0)
(Carrots, Usability, 0.0)
(Carrots, Size, 0.0)

or

(Carrots, Flavour, 2.0)
(Carrots, Smell, null)
(Carrots, Usability, null)
(Carrots, Size, null)

Or am I missing something? I tested it btw =P


On 5 Dez, 23:42, Reinout van Rees  wrote:
> On 05-12-11 23:10, wgis wrote:
>
>
>
>
>
>
>
>
>
> > Hi guys,
> > I'm trying to solve this without raw SQL, from the past 4/5 days.
> > I've been also researching a lot to understand more complex queries in
> > django so I would realy appreciate your help since I plan to continue
> > using django in my projects.
>
> > I have a:
>
> > class VoteContext(models.Model):
>
> >    name = models.CharField(max_length = 15, unique = True)
>
> > class Vote(models.Model):
>
> >    thing = models.ForeignKey(Thing, null = False)
> >    context = models.ForeignKey(VoteContext, null = False)
> >    user = models.ForeignKey(User, null = False)
> >    vote = models.DecimalField(default = 0, max_digits = 3,
> > decimal_places = 1, null = False)
>
> >          class Meta:
> >            unique_together = ("thing", "user", "context")
>
> > Something like this in the database: (I will put names instead of IDs
> > for easier understanding)
>
> > mydatabase_votecontext
> > (id, name)
> > (1, Flavour)
> > (2, Smell)
> > (3, Usability)
> > (4, Size)
>
> > mydatabase_vote
> > (id, thing, context, user, vote)
>
> > (1, Potatoes, Flavour, Me, 2.0)
> > (2, Potatoes, Smell, Me, 4.3)
> > (3, Potatoes, Usability, Me, 4.0)
> > (4, Carrots, Flavor, Me, 3.0)
> > (5, Cars, Smell, Me, 4.2)
> > (6, Cars, Usability, Me, 4.9)
>
> > I would like to make a query for ->  one specific "thing"<-, like,
> > Carrots, being the result:
>
> > (Carrots, Flavour, 2.0)
> > (Carrots, Smell, 0.0)
> > (Carrots, Usability, 0.0)
> > (Carrots, Size, 0.0)
>
> > or
>
> > (Carrots, Flavour, 2.0)
> > (Carrots, Smell, null)
> > (Carrots, Usability, null)
> > (Carrots, Size, null)
>
> So what you want to get back is votes, right?
>
> Vote.objects.all()
>
> But... filtered for one specific thing:
>
> Vote.objects.filter(thing=carrot)  # Assuming carrot is known.
> Vote.objects.filter(thing__id=4)  # Assuming you want it by ID.
>
> And then you only want three specific values:
>
> Vote.objects.filter(thing=carrot).values_list('thing', 'context', 'vote)
>
> Seehttps://docs.djangoproject.com/en/1.3/ref/models/querysets/#values-list
> for how that last trick works.
>
> Something like that?
>
> Reinout
>
> --
> Reinout van Rees                    http://reinout.vanrees.org/
> rein...@vanrees.org            http://www.nelen-schuurmans.nl/
> "If you're not sure what to do, make something. -- Paul Graham"

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



avoid/defer pk select call in getting model object via foreign key

2011-12-05 Thread vanatteveldt
Dear group,

I have two models in a foreign key relation. The 'master' table is
extremely simple, having only the primary key field. The child table
has multiple fields. (The rationale for the master table is that it
has FK relations to a number of otherwise unrelated tables.)

My use case is that I have a bunch of child model objects, and I want
to get their master model object. The naive code would be something
like

masters = [c.master for c in children]

Since the foreign key is not null, we are ensured that c.master must
exist. Moreover, there are no additional fields to query. So, the
above should not need to result in a database call, as there is no new
information to gather. Unfortunately, Django makes a (pretty silly)
"select master.id from masters where master.id = X" call for each
child object. Now there can easily be thousands of children, so this
is not a trivial expense.

I've tried various things like

[Masters.objects.filter(pk=c.master_id).defer()[0] for c in children]

But Django seems to insist on querying the primary key (which would
normally make sense as an existence check, although it would be nice
if this check could be deferred as well).

Obviously, I could use [c.master_id for c in children] instead, but I
hate passing integers around when I mean model objects (eg the model
identity is lost).

I guess in this case I could call the constructor directly (eg
[Masters(id=c.master_id) for c in children]), but I think the
assumption is that this would be a *new* object to be saved, so if
other code would call m.save() it will try to insert the record.

Is there a way to get the master model objects without invoking the
database?

If not, what is the preferred way to get the objects with a single
query?
list(Master.objects.filter(id__in=[c.master_id for c in all]))
This call works, but is Django smart enough to break that into
multiple queries if the list becomes too large to "fit" in a single
query (I think most DB backends have some sort of limit on query
length...)

Thanks a lot,

Wouter

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can't figure out this Object Model error...

2011-12-05 Thread Furbee
That is what I sort of assumed. You created the table with syncdb, changed
the models.py for it and ran syncdb, which does nothing if the table
already exists.


On Mon, Dec 5, 2011 at 5:04 PM, Reinout van Rees wrote:

> On 06-12-11 01:24, Marc Edwards wrote:
>
>> DatabaseError at/admin/bookmarks/eda_**appcatalog/
>>
>> no such column: bookmarks_eda_appcatalog.eda_**app_id
>>
>
> The "eda_app_id" colum is what Django uses to store the foreign key. You
> probably added the foreign key after creating the EDA_AppCatalog class.
> Your syncdb after creating EDA_AppCatalog created the table.
>
> After adding the foreign key, the table already exists, so syncdb doesn't
> do anything. For adding columns to existing tables, syncdb is useless.
>
> - Either create the column by hand.
>
> - Delete the table and re-create it with syncdb (it will now contain the
> foreign key column).
>
> - Use south for database migrations.
>
>
>
>
> Reinout
>
> --
> Reinout van Reeshttp://reinout.vanrees.org/
> rein...@vanrees.org 
> http://www.nelen-schuurmans.**nl/
> "If you're not sure what to do, make something. -- Paul Graham"
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Template filter with multiple non-string arguments?

2011-12-05 Thread Nan
So, yes, I know one can combine template filter arguments by quoting
them into a single concatenated string...  But what if one needs to do
something that amounts to the following?

{% for object in object_list %}
{{ some_other_var|custom_filter(constant_string, object.field)|
some_other_filter|etc }}
{% endfor %}

Obviously one can't within the loop convert the argument list into a
string.  Is there any workaround for this that isn't horribly ugly?

Using Django 1.2, btw.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can't figure out this Object Model error...

2011-12-05 Thread Reinout van Rees

On 06-12-11 01:24, Marc Edwards wrote:

DatabaseError at/admin/bookmarks/eda_appcatalog/

no such column: bookmarks_eda_appcatalog.eda_app_id


The "eda_app_id" colum is what Django uses to store the foreign key. You 
probably added the foreign key after creating the EDA_AppCatalog class. 
Your syncdb after creating EDA_AppCatalog created the table.


After adding the foreign key, the table already exists, so syncdb 
doesn't do anything. For adding columns to existing tables, syncdb is 
useless.


- Either create the column by hand.

- Delete the table and re-create it with syncdb (it will now contain the 
foreign key column).


- Use south for database migrations.




Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can't figure out this Object Model error...

2011-12-05 Thread Marc Edwards
Even when I delete the class definition, re-sync the db, and then re-
define the object, even setting the primary_key=True on a new
CharField, I am still receiving the same error.

Can it be that the database file has become corrupted in some manner
for this object.  I have not modified my SQLite file in any way except
through the admin interface.

On Dec 5, 7:44 pm, Marc Edwards  wrote:
> This is the confusing part.  The EDA_AppCatalog imports from my
> bookmarks package with no problem.
>
> My class definition for this object has only 1 field, a ForeignKey to
> an EDA_App.
>
> I know that the Object Model will be assigning an "ID" to the object
> when it stores it in the database.  I am not assigning this ID field.
> I also don't do this with the other object models that I have defined
> and that seem to be working with no problem.
>
> Why the admin interface is complaining about this ID field even before
> I have even instantiated an initial EDA_App to add to the database is
> strange.
>
> I have another object defined that uses 3 ForeignKeys that works fine
> in the admin interface.  There seems to be something that is not
> defined properly with this particular object definition.
>
> -M
>
> On Dec 5, 7:35 pm, Furbee  wrote:
>
>
>
>
>
>
>
> > Don't mean to sound remedial, but have you verified that the table
> > bookmarks_eda_appcatalog exists and that it has a column named eda_app_id?
> > Did you use manage.py syncdb to create the tables?
>
> > Furbee
>
> > On Mon, Dec 5, 2011 at 4:24 PM, Marc Edwards  wrote:
> > > I am receiving the following error from the Django debugger when
> > > trying to access my EDA_AppCatalog object.  My class definition is
> > > listed below.  I have similar defined objects that are working with no
> > > problem, but I can't seem to clear this error message up.
>
> > > Thanks, Marc
>
> > > DatabaseError at /admin/bookmarks/eda_appcatalog/
>
> > > no such column: bookmarks_eda_appcatalog.eda_app_id
>
> > > Request Method:         GET
> > > Request URL:    http://127.0.0.1:8000/admin/bookmarks/eda_appcatalog/
> > > Django Version:         1.3.1
> > > Exception Type:         DatabaseError
> > > Exception Value:
>
> > > no such column: bookmarks_eda_appcatalog.eda_app_id
>
> > > Exception Location:     /usr/local/lib/python2.7/dist-packages/django/db/
> > > backends/sqlite3/base.py in execute, line 234
> > > Python Executable:      /usr/bin/python2.7
> > > Python Version:         2.7.2
> > > Python Path:
>
> > > ['/home/jmarcedwards/KeplerDevelopment/KeplerEclipseWorkspace_1/
> > > JME_DjangoTest_3/JME_DjangoTest_3',
>
> > > ---
> > >  
> > > class EDA_AppCatalog(models.Model):
>
> > >    eda_app = models.ForeignKey(EDA_App)
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Django users" group.
> > > To post to this group, send email to django-users@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to format string on I18n

2011-12-05 Thread rskm1
On Dec 5, 6:05 am, Tsung-Hsien  wrote:
> I have been delete the "#, fuzzy" and remain the "#, python-format",
> but the string still show English.

You do need to remove the ", fuzzy" in order for the translations to
be used.
But you also need to recompile the .mo files after you make any
changes to the .po files.
https://docs.djangoproject.com/en/1.3/topics/i18n/localization/#compiling-message-files

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can't figure out this Object Model error...

2011-12-05 Thread Marc Edwards
This is the confusing part.  The EDA_AppCatalog imports from my
bookmarks package with no problem.

My class definition for this object has only 1 field, a ForeignKey to
an EDA_App.

I know that the Object Model will be assigning an "ID" to the object
when it stores it in the database.  I am not assigning this ID field.
I also don't do this with the other object models that I have defined
and that seem to be working with no problem.

Why the admin interface is complaining about this ID field even before
I have even instantiated an initial EDA_App to add to the database is
strange.

I have another object defined that uses 3 ForeignKeys that works fine
in the admin interface.  There seems to be something that is not
defined properly with this particular object definition.

-M

On Dec 5, 7:35 pm, Furbee  wrote:
> Don't mean to sound remedial, but have you verified that the table
> bookmarks_eda_appcatalog exists and that it has a column named eda_app_id?
> Did you use manage.py syncdb to create the tables?
>
> Furbee
>
>
>
>
>
>
>
> On Mon, Dec 5, 2011 at 4:24 PM, Marc Edwards  wrote:
> > I am receiving the following error from the Django debugger when
> > trying to access my EDA_AppCatalog object.  My class definition is
> > listed below.  I have similar defined objects that are working with no
> > problem, but I can't seem to clear this error message up.
>
> > Thanks, Marc
>
> > DatabaseError at /admin/bookmarks/eda_appcatalog/
>
> > no such column: bookmarks_eda_appcatalog.eda_app_id
>
> > Request Method:         GET
> > Request URL:    http://127.0.0.1:8000/admin/bookmarks/eda_appcatalog/
> > Django Version:         1.3.1
> > Exception Type:         DatabaseError
> > Exception Value:
>
> > no such column: bookmarks_eda_appcatalog.eda_app_id
>
> > Exception Location:     /usr/local/lib/python2.7/dist-packages/django/db/
> > backends/sqlite3/base.py in execute, line 234
> > Python Executable:      /usr/bin/python2.7
> > Python Version:         2.7.2
> > Python Path:
>
> > ['/home/jmarcedwards/KeplerDevelopment/KeplerEclipseWorkspace_1/
> > JME_DjangoTest_3/JME_DjangoTest_3',
>
> > --- 
> > 
> > class EDA_AppCatalog(models.Model):
>
> >    eda_app = models.ForeignKey(EDA_App)
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can't figure out this Object Model error...

2011-12-05 Thread Furbee
Don't mean to sound remedial, but have you verified that the table
bookmarks_eda_appcatalog exists and that it has a column named eda_app_id?
Did you use manage.py syncdb to create the tables?

Furbee

On Mon, Dec 5, 2011 at 4:24 PM, Marc Edwards  wrote:

> I am receiving the following error from the Django debugger when
> trying to access my EDA_AppCatalog object.  My class definition is
> listed below.  I have similar defined objects that are working with no
> problem, but I can't seem to clear this error message up.
>
> Thanks, Marc
>
> DatabaseError at /admin/bookmarks/eda_appcatalog/
>
> no such column: bookmarks_eda_appcatalog.eda_app_id
>
> Request Method: GET
> Request URL:http://127.0.0.1:8000/admin/bookmarks/eda_appcatalog/
> Django Version: 1.3.1
> Exception Type: DatabaseError
> Exception Value:
>
> no such column: bookmarks_eda_appcatalog.eda_app_id
>
> Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/
> backends/sqlite3/base.py in execute, line 234
> Python Executable:  /usr/bin/python2.7
> Python Version: 2.7.2
> Python Path:
>
> ['/home/jmarcedwards/KeplerDevelopment/KeplerEclipseWorkspace_1/
> JME_DjangoTest_3/JME_DjangoTest_3',
>
> ---
> class EDA_AppCatalog(models.Model):
>
>eda_app = models.ForeignKey(EDA_App)
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Can't figure out this Object Model error...

2011-12-05 Thread Marc Edwards
I am receiving the following error from the Django debugger when
trying to access my EDA_AppCatalog object.  My class definition is
listed below.  I have similar defined objects that are working with no
problem, but I can't seem to clear this error message up.

Thanks, Marc

DatabaseError at /admin/bookmarks/eda_appcatalog/

no such column: bookmarks_eda_appcatalog.eda_app_id

Request Method: GET
Request URL:http://127.0.0.1:8000/admin/bookmarks/eda_appcatalog/
Django Version: 1.3.1
Exception Type: DatabaseError
Exception Value:

no such column: bookmarks_eda_appcatalog.eda_app_id

Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/
backends/sqlite3/base.py in execute, line 234
Python Executable:  /usr/bin/python2.7
Python Version: 2.7.2
Python Path:

['/home/jmarcedwards/KeplerDevelopment/KeplerEclipseWorkspace_1/
JME_DjangoTest_3/JME_DjangoTest_3',
---
class EDA_AppCatalog(models.Model):

eda_app = models.ForeignKey(EDA_App)






































































-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Query with no-correspondence results

2011-12-05 Thread Reinout van Rees

On 05-12-11 23:10, wgis wrote:

Hi guys,
I'm trying to solve this without raw SQL, from the past 4/5 days.
I've been also researching a lot to understand more complex queries in
django so I would realy appreciate your help since I plan to continue
using django in my projects.



I have a:

class VoteContext(models.Model):

name = models.CharField(max_length = 15, unique = True)

class Vote(models.Model):

thing = models.ForeignKey(Thing, null = False)
context = models.ForeignKey(VoteContext, null = False)
user = models.ForeignKey(User, null = False)
vote = models.DecimalField(default = 0, max_digits = 3,
decimal_places = 1, null = False)

 class Meta:
unique_together = ("thing", "user", "context")


Something like this in the database: (I will put names instead of IDs
for easier understanding)

mydatabase_votecontext
(id, name)
(1, Flavour)
(2, Smell)
(3, Usability)
(4, Size)

mydatabase_vote
(id, thing, context, user, vote)

(1, Potatoes, Flavour, Me, 2.0)
(2, Potatoes, Smell, Me, 4.3)
(3, Potatoes, Usability, Me, 4.0)
(4, Carrots, Flavor, Me, 3.0)
(5, Cars, Smell, Me, 4.2)
(6, Cars, Usability, Me, 4.9)


I would like to make a query for ->  one specific "thing"<-, like,
Carrots, being the result:

(Carrots, Flavour, 2.0)
(Carrots, Smell, 0.0)
(Carrots, Usability, 0.0)
(Carrots, Size, 0.0)

or

(Carrots, Flavour, 2.0)
(Carrots, Smell, null)
(Carrots, Usability, null)
(Carrots, Size, null)


So what you want to get back is votes, right?

Vote.objects.all()


But... filtered for one specific thing:

Vote.objects.filter(thing=carrot)  # Assuming carrot is known.
Vote.objects.filter(thing__id=4)  # Assuming you want it by ID.


And then you only want three specific values:

Vote.objects.filter(thing=carrot).values_list('thing', 'context', 'vote)

See
https://docs.djangoproject.com/en/1.3/ref/models/querysets/#values-list
for how that last trick works.


Something like that?


Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: djangopeople.net

2011-12-05 Thread Russell Keith-Magee
On Tue, Dec 6, 2011 at 6:48 AM, Vitaliy  wrote:
> Hi,
>
> seems http://djangopeople.net gone, anyone know if going to be up or
> who is running it ?..
> I just lost one contact that I definitely know exist on that site :(

Hi Vitaly,

djangopeople.net has historically been managed by Simon Willison.
However, he's been busy with his own projects, so djangopeople.net
hasn't got the attention it needs to keep it running.

There was an effort a few months back to resurrect djangopeople.net,
as well as a second project under a different domain
(djangopeople.me). I'm not sure what has come of either of these.
However, if the people involved in those projects are still
interested, the DSF is willing to provide hosting and support to
improve and maintain this resource for the community.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: djangopeople.net

2011-12-05 Thread Kurtis Mullins
http://www.networksolutions.com/whois-search/djangopeople.net

On Mon, Dec 5, 2011 at 5:48 PM, Vitaliy  wrote:

> Hi,
>
> seems http://djangopeople.net gone, anyone know if going to be up or
> who is running it ?..
> I just lost one contact that I definitely know exist on that site :(
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



djangopeople.net

2011-12-05 Thread Vitaliy
Hi,

seems http://djangopeople.net gone, anyone know if going to be up or
who is running it ?..
I just lost one contact that I definitely know exist on that site :(

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Query with no-correspondence results

2011-12-05 Thread wgis
Hi guys,
I'm trying to solve this without raw SQL, from the past 4/5 days.
I've been also researching a lot to understand more complex queries in
django so I would realy appreciate your help since I plan to continue
using django in my projects.



I have a:

class VoteContext(models.Model):

name = models.CharField(max_length = 15, unique = True)

class Vote(models.Model):

thing = models.ForeignKey(Thing, null = False)
context = models.ForeignKey(VoteContext, null = False)
user = models.ForeignKey(User, null = False)
vote = models.DecimalField(default = 0, max_digits = 3,
decimal_places = 1, null = False)

class Meta:
unique_together = ("thing", "user", "context")


Something like this in the database: (I will put names instead of IDs
for easier understanding)

mydatabase_votecontext
(id, name)
(1, Flavour)
(2, Smell)
(3, Usability)
(4, Size)

mydatabase_vote
(id, thing, context, user, vote)

(1, Potatoes, Flavour, Me, 2.0)
(2, Potatoes, Smell, Me, 4.3)
(3, Potatoes, Usability, Me, 4.0)
(4, Carrots, Flavor, Me, 3.0)
(5, Cars, Smell, Me, 4.2)
(6, Cars, Usability, Me, 4.9)


I would like to make a query for -> one specific "thing" <-, like,
Carrots, being the result:

(Carrots, Flavour, 2.0)
(Carrots, Smell, 0.0)
(Carrots, Usability, 0.0)
(Carrots, Size, 0.0)

or

(Carrots, Flavour, 2.0)
(Carrots, Smell, null)
(Carrots, Usability, null)
(Carrots, Size, null)


Thanks in advance

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Pointing to Memcached on Remote Server

2011-12-05 Thread mattym
Thanks all -

I stepped away from this issue for a few days.  I am confident this
thread will point me in the right direction.

I did notice with nmap I am getting:

PORT  STATE  SERVICE
11211/tcp closed unknown

I will be digging into this issue again soon and this thread helps!
Thanks again

On Dec 3, 1:43 pm, huseyin yilmaz  wrote:
> Also check memcached configuration (/etc/memcached.conf)
> from this file,you can limit IP addresses that memcached listening to
> here is a configuration parameter that you might have
>
> # Specify which IP address to listen on. The default is to listen on
> all IP
> addresses
> # This parameter is one of the only security measures that memcached
> has, so make
> sure
> # it's listening on a firewalled
> interface.
> #-l 127.0.0.1
>
> On Dec 2, 3:49 am, mattym  wrote:
>
>
>
>
>
>
>
> > Hi all -
>
> > I am stuck on this one. Caching with memcached works when I reference
> > the local box holding Django. But when I point my setting to a remote
> > box it does not cache:
>
> > This is with Django 1.3 using python-memcached on the localbox in a
> > virtualenv
>
> >  'default': {
> >         'BACKEND':
> > 'django.core.cache.backends.memcached.MemcachedCache',
> >         #'LOCATION': ['127.0.0.1:11211',]  # This works
> >         'LOCATION': ['xx.xxx.xxx.xx:11211',]  # This remote one does not
> >     }
>
> > My settings file appears to have the proper middleware installed:
>
> >  "django.middleware.gzip.GZipMiddleware",
> >   "django.middleware.cache.UpdateCacheMiddleware",
> >     "django.contrib.sessions.middleware.SessionMiddleware",
> >     "django.contrib.auth.middleware.AuthenticationMiddleware",
> >     "django.contrib.redirects.middleware.RedirectFallbackMiddleware",
> >     "mezzanine.core.middleware.DeviceAwareUpdateCacheMiddleware",
> >     "django.middleware.common.CommonMiddleware",
> >     "django.middleware.csrf.CsrfViewMiddleware",
> >     "mezzanine.core.middleware.DeviceAwareFetchFromCacheMiddleware",
> >     "mezzanine.core.middleware.AdminLoginInterfaceSelector",
> >     "django.middleware.cache.FetchFromCacheMiddleware",
>
> > I've checked that memcached is running on the remote box. I am
> > probably overlooking something simple.
> > Any help is greatly appreciated.
>
> > Thanks,
> > Matt

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Conditional choice fields for model specification...

2011-12-05 Thread Marc Edwards
I would like to create my choice fields in my models according to a
hierarchy of conditions, but I can't think of how to specify this in
Python.

For example...pseudo code...

class mod1(models.Model):

choice1 = (
  ('a', 'A'),
  ('b', 'B'),
)

choice_a_if_choice1_is_A = (
   ('z', 'Z'),
   ('y', 'Y'),
)

choice_a_if_choice1_is_B = (
('m', 'M')
('n', 'N')
)

field1 = models.CharField(max_length=30, choices=choice1)

field2 = models.CharField(max_length=30,
choices=choice_a_if_choice_is_A)
field2 = models.CharField(max_length=30,
choices=choice_a_if_choice_is_B)

How to I set the choices for field2 depending upon the choice
selected in field1??

)

Kind regards, Marc

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



cache problem but query is OK

2011-12-05 Thread galgal
I try to make a very simple cache usage:
myquery = 
UserProfile.objects.select_related('user').filter(status__exact=1).values_list('user__username',
 
'q_points').order_by('-q_points')[:50]
cache.set('test_cache', myquery, 3600)
print cache.get('test_cache')
I get an error:
UserProfile has no field named 'username'
The thing is query is OK and returns valid results.

Debug Toolbar shows that cache value:
([(u'admin', 2L), (user1', 0L), (testuser', 0L)], 3600)

I have no idea what is wrong :/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/4-Bdfxea-_UJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Bulk import of data

2011-12-05 Thread Victor Hooi
heya,

Hmm, I was previously under the impression that for these sorts of things 
(importing and instantiating models from CSV), the recommended way to 
create a ModelForm, and pass each line of the CSV through that, and have 
that handle model validation for you.

In our case, we have a CSV file, but quite a few of those lines are 
probably invalid/erroneous - we need to provide useful messages on those, 
and import the rest of the file.

Is the recommended way now to use bulk_create 
(https://docs.djangoproject.com/en/dev/ref/models/querysets/#bulk-create), 
process all the lines, and hit that in one call?

How would you handle invalid lines or validation errors for individual rows?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/qYfAZWsydQoJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: New design for class-based views

2011-12-05 Thread Javier Guerra Giraldez
On Mon, Dec 5, 2011 at 10:07 AM, sebastien piquemal  wrote:
> Could you post a link to a place where class-based views are being
> criticized ? And also in what sense are they convoluted ?

i have previously expressed some problems with CBVs, maybe not so
solid as criticism; but i understand the point of view of calling them
'seemingly overcomplex'.

i think the problem is that a classical Django view fits a very
procedural niche: generate the response for this request.  seems
almost like the definition of a function, no?  therefore using OOD to
get better modularity _inside_ this specific niche is far from
obvious.  Right now, the CBVs are documented only in the 'what they
do', but not in the 'how to use', nor in the 'why are they like that'.

In the end, i had to read lots of class definitions, keeping track of
what is implemented at what level to see which class to use, whether
to instantiate or inherit it, and where to override what; all the
while thinking that I wlaready knew how to do that with the old
generic views.

in some cases, after i had it working with CBVs, when i had to extend
functionality a little more, i finally wrote a classic view function
instead.

Does that mean that they're overly complex?  maybe

Would a simpler design be easier to use?  sure, but only on the simple cases

Does the current design holds up for the complex cases?  i don't know,
but hope so.  For me, that's the real problem.  without the 'how to
use' docs, i don't have any hint about when to make the effort to stay
with CBV (to learn them better) and when to write case-specific code.

-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: New design for class-based views

2011-12-05 Thread Javier Guerra Giraldez
On Mon, Dec 5, 2011 at 12:37 PM, Reinout van Rees  wrote:
> On 03-12-11 19:56, Tobia Conforto wrote:
>>
>> Here is the View base class:http://dpaste.com/hold/665528/
>
> That link will expire in a month, so that's not really suited to posting on
> a mailinglist that people might still read a month from now.

hopefully this proposal will either evolve into something popular, or
else get some better insights on current CBV, in far less than a
month.  in either case, this specific code snippet becomes unneeded.


-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Transaction not working with test

2011-12-05 Thread Javier Guerra Giraldez
On Mon, Dec 5, 2011 at 10:52 AM, anthony tresontani
 wrote:
> I am using Django 1.3, django-nose, sqlite inmemory database.
>
> I tried with TestCase,TransactionTestCase, commit_on_success
> (decorator and context manager) and commit_manually. None of them
> worked.

i'm successfully testing transaction rollbacks.  I use
commit_on_success decorator, but only because it was the easiest way
to express my needs.  manually and/or context managers seem to work
too, but haven't tried.

at first it didn't work, but simply switching those tests to inherit
from TransactionTestCase instead of the usual TestCase did the trick.
that's with SQLite3 in-memory database for tests and MySQL InnoDB for
deployment.

I haven't used django-nose, so that might be a difference.


> Am I doing or expecting something wrong?

mostly expecting people to magically get insights on your code without
seeing it.

to get anything beyond "works for me", you'll have to show some code
and what you're expecting/getting.


-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: New design for class-based views

2011-12-05 Thread Reinout van Rees

On 03-12-11 19:56, Tobia Conforto wrote:

Here is the View base class:http://dpaste.com/hold/665528/


That link will expire in a month, so that's not really suited to posting 
on a mailinglist that people might still read a month from now.


I think most of those copy-paste sites have a "keep forever" option?


Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: AW: Performance

2011-12-05 Thread Tim Sawyer
http://pypi.python.org/pypi/django-debug-toolbar will show the number of
queries, time taken to query, and allow you to see the stack trace for the
code that caused the query to be executed.

Hope that helps,

Tim.

> On Dec 5, 2011, at 3:18 AM, Szabo, Patrick (LNG-VIE) wrote:
>
>> Okay that toolbar is really useful and also looks kind of nice J…Thanks
>> for that.
>> I’ve already found the problem….somehow my app triggers 800 queries just
>> for a simple page.
>> Can I somehow find out which part of my code is causing those queries ?!
>>
>> patrick
>>
>>
>> . . . . . . . . . . . . . . . . . . . . . . . . . .
>> Ing. Patrick Szabo
>> XSLT Developer
>> LexisNexis
>> Marxergasse 25, 1030 Wien
>>
>> patrick.sz...@lexisnexis.at
>> Tel.: 00431 534521573
>> Fax: +43 (1) 534 52 - 146
>>
>> Von: django-users@googlegroups.com
>> [mailto:django-users@googlegroups.com] Im Auftrag von Nikolas
>> Stevenson-Molnar
>> Gesendet: Montag, 05. Dezember 2011 08:14
>> An: Nikolas Stevenson-Molnar
>> Cc: django-users@googlegroups.com
>> Betreff: Re: Performance
>>
>> A bit more searching turned up something even better... looks like the
>> Django folks address this directly:
>> https://code.djangoproject.com/wiki/ProfilingDjango
>>
>> _Nik
>>
>> On Dec 4, 2011, at 11:03 PM, Nikolas Stevenson-Molnar wrote:
>>
>>
>> I haven't done this myself, but I would assume you could use the Python
>> profiler. Here's one project that facilitates profiling a WSGI app
>> (assuming you're using Django via WSGI): http://repoze.org/
>>
>> Others here may have more experience with profiling web apps.
>>
>> _Nik
>>
>> On Dec 4, 2011, at 10:55 PM, Szabo, Patrick (LNG-VIE) wrote:
>>
>>
>> Hi,
>>
>> In the last couple of weeks my app has become quite slowly and I’m
>> wondering why that is.
>> Are there any debugging tools where I can see what takes how much time ?
>>
>> cheers
>>
>> . . . . . . . . . . . . . . . . . . . . . . . . . .
>> Ing. Patrick Szabo
>> XSLT Developer
>> LexisNexis
>> Marxergasse 25, 1030 Wien
>>
>> patrick.sz...@lexisnexis.at
>> Tel.: 00431 534521573
>> Fax: +43 (1) 534 52 - 146
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: AW: Performance

2011-12-05 Thread Felipe Morales
Patrick,

try to use select_related() method instead of only filter() when you get a
list of elements, e.g. :

queryset = Model.objects.filter().select_related()

by this way you'll get only one query instead 800

good luck!

Felipe

2011/12/5 Nikolas Stevenson-Molnar 

> It would help to know a little more about your code here. Could you give
> some examples?
>
> _NIk
>
> On Dec 5, 2011, at 3:18 AM, Szabo, Patrick (LNG-VIE) wrote:
>
>  Okay that toolbar is really useful and also looks kind of nice J…Thanks
> for that.
> I’ve already found the problem….somehow my app triggers 800 queries just
> for a simple page.
> Can I somehow find out which part of my code is causing those queries ?!**
> **
> ** **
> patrick
> ** **
>
> . . . . . . . . . . . . . . . . . . . . . . . . . .
>
> **
> Ing. Patrick Szabo
> XSLT Developer
> LexisNexis
> Marxergasse 25, 1030 Wien
>
> patrick.sz...@lexisnexis.at
>  Tel.: 00431 534521573
> Fax: +43 (1) 534 52 - 146
>
>
> *Von:* django-users@googlegroups.com [mailto:django-users@googlegroups.com
> ] *Im Auftrag von *Nikolas Stevenson-Molnar
> *Gesendet:* Montag, 05. Dezember 2011 08:14
> *An:* Nikolas Stevenson-Molnar
> *Cc:* django-users@googlegroups.com
> *Betreff:* Re: Performance
> ** **
> A bit more searching turned up something even better... looks like the
> Django folks address this directly:
> https://code.djangoproject.com/wiki/ProfilingDjango
> ** **
> _Nik
> ** **
> On Dec 4, 2011, at 11:03 PM, Nikolas Stevenson-Molnar wrote:
>
>
> 
> I haven't done this myself, but I would assume you could use the Python
> profiler. Here's one project that facilitates profiling a WSGI app
> (assuming you're using Django via WSGI): http://repoze.org/
> ** **
> Others here may have more experience with profiling web apps.
> ** **
> _Nik
> ** **
> On Dec 4, 2011, at 10:55 PM, Szabo, Patrick (LNG-VIE) wrote:
>
>
> 
> Hi,
>  
> In the last couple of weeks my app has become quite slowly and I’m
> wondering why that is.
> Are there any debugging tools where I can see what takes how much time ?**
> **
>  
> cheers
> ** **
> . . . . . . . . . . . . . . . . . . . . . . . . . .
> Ing. Patrick Szabo
> XSLT Developer
> LexisNexis
> Marxergasse 25, 1030 Wien
>
> patrick.sz...@lexisnexis.at
> Tel.: 00431 534521573
> Fax: +43 (1) 534 52 - 146
> ** **
> ** **
> ** **
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
> ** **
> ** **
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Felipe Morales C.
Ingenierío de Ejecución en Computación e Informática.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: AW: Performance

2011-12-05 Thread Nikolas Stevenson-Molnar
It would help to know a little more about your code here. Could you give some 
examples?

_NIk

On Dec 5, 2011, at 3:18 AM, Szabo, Patrick (LNG-VIE) wrote:

> Okay that toolbar is really useful and also looks kind of nice J…Thanks for 
> that.
> I’ve already found the problem….somehow my app triggers 800 queries just for 
> a simple page.
> Can I somehow find out which part of my code is causing those queries ?!
>  
> patrick
>  
> 
> . . . . . . . . . . . . . . . . . . . . . . . . . .
> Ing. Patrick Szabo
> XSLT Developer
> LexisNexis
> Marxergasse 25, 1030 Wien
> 
> patrick.sz...@lexisnexis.at
> Tel.: 00431 534521573
> Fax: +43 (1) 534 52 - 146
> 
> Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] Im 
> Auftrag von Nikolas Stevenson-Molnar
> Gesendet: Montag, 05. Dezember 2011 08:14
> An: Nikolas Stevenson-Molnar
> Cc: django-users@googlegroups.com
> Betreff: Re: Performance
>  
> A bit more searching turned up something even better... looks like the Django 
> folks address this directly: 
> https://code.djangoproject.com/wiki/ProfilingDjango
>  
> _Nik
>  
> On Dec 4, 2011, at 11:03 PM, Nikolas Stevenson-Molnar wrote:
> 
> 
> I haven't done this myself, but I would assume you could use the Python 
> profiler. Here's one project that facilitates profiling a WSGI app (assuming 
> you're using Django via WSGI): http://repoze.org/
>  
> Others here may have more experience with profiling web apps.
>  
> _Nik
>  
> On Dec 4, 2011, at 10:55 PM, Szabo, Patrick (LNG-VIE) wrote:
> 
> 
> Hi,
>  
> In the last couple of weeks my app has become quite slowly and I’m wondering 
> why that is.
> Are there any debugging tools where I can see what takes how much time ?
>  
> cheers
>  
> . . . . . . . . . . . . . . . . . . . . . . . . . .
> Ing. Patrick Szabo
> XSLT Developer
> LexisNexis
> Marxergasse 25, 1030 Wien
> 
> patrick.sz...@lexisnexis.at
> Tel.: 00431 534521573
> Fax: +43 (1) 534 52 - 146
>  
>  
>  
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>  
>  
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Transaction not working with test

2011-12-05 Thread anthony tresontani
Hey Guys,

I am trying to test a transaction rollback in a unit test and it seems
to not work properly.

I am using Django 1.3, django-nose, sqlite inmemory database.

I tried with TestCase,TransactionTestCase, commit_on_success
(decorator and context manager) and commit_manually. None of them
worked.

Am I doing or expecting something wrong?

Thanks,

Anthony

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: slow function

2011-12-05 Thread Håkon Erichsen
2011/12/5 Brian Schott 

> What's the best dangothonic way to break up models.py or views.py for that
> matter.
> 1. Create a models.py or views.py at the top level that does a bunch of
> imports?  Explicitly or progrmmatically by looping over files?
> 2. Expose the hierarchy to the caller.  Ex: from my_app.models.my_model
> import MyModel
> 3. Break up the whole app into smaller apps?
>
> Still trying to figure out a good way to determine what should be a
> separate app.  If you have a relathionships like Publishers -> Books, and
> Authors -> Books should you try to break out Books, Authors, and Publishers
> as separate apps?
>

For views, I think the most djangoic (?) way is making a *app*/views/
package, and then put separate files there. You can import the views in
 *app*/views/__init__.py if you want, but it's really not necessary: I find
that e.g. "from user.views.permissions import edit" looks pretty well, and
the django admin does this as well.

For models: See https://code.djangoproject.com/ticket/4470 and
https://code.djangoproject.com/ticket/3591 .  (In other words: Currently
not possible in a pretty way).The currently best method is probably the one
with a _models directory, or defining the app_label. but this might be
fixed soon, the tickets have som recent activity :)

Best regards,
Håkon Erichsen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Nesting spatial filters with the __in filter will be broken until I buy you a beer.

2011-12-05 Thread jpk
Hi all,

I've recently been using the __in filter, and it's pretty nifty.
However, it seems that nesting any of geodjango's spatial filters with
the __in filter is busted.  This ticket:
https://code.djangoproject.com/ticket/17314 explains the behavior in
detail, but the précis is: "things =
Thing.objects.filter(point_field__contained=Polygon(...))" followed by
"other_things = OtherThing.objects.filter(thing__in=things)" results
in the sql compiler blowing up when the query for other_things is
supposed run.

This is a major pain in two apps I'm working on, and I'll sponsor
patches with things including but not limited to:
 * Free beer
 * Homemade cupcakes
 * Hugs

Or, if you have the inhuman inclination to refuse the aforementioned
bribery, I can probably fix the issue with some direction (which would
still be met with considerable gratitude).

Thanks,
jpk

-- 


John P. Kiffmeyer
Email/XMPP: j...@thekiffmeyer.org

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: New design for class-based views

2011-12-05 Thread sebastien piquemal
Hi Tobia !

Could you post a link to a place where class-based views are being
criticized ? And also in what sense are they convoluted ?

Personally, I have started using the class-based views heavily as soon
as they were released, and I think they are great. Very flexible.
However, I'll tell you what I usually do (and if you don't, it's just
not possible) : browsing the Django code online, every time I need to
customize a view. So in my sense, there is much more room for
improvement in the class-based views docs than in their actual API ...

Sébastien

On Dec 3, 8:56 pm, Tobia Conforto  wrote:
> Hello
>
> As you may know, current class-based views have been criticized for
> their complexity.
>
> Their design is a bit convoluted and difficult to understand by the
> average view author and therefore any work made with them may hide
> sneaky bugs.
>
> On top of that, it's difficult to apply common decorators to them. The
> recommended approach seems to be to apply them to the dispatch()
> method. But this requires overriding that method even when the base
> dispatch strategy is otherwise adequate, and converting the decorators
> with method_decorator(). This is ugly and is only a partial solution,
> as method_decorator() doesn't currently support decorators with
> arguments, such as @user_passes_test(a_test).
>
> All this is unfortunate, because there is a clear need for a simple,
> Pythonic object-oriented approach to view authoring, to achieve
> separation of concerns and code reuse. Dispatching by http method (one
> of the basic features of class-based views) is also a growing need, in
> the world of AJAX and REST-based web applications.
>
> I have attached my proposal for a slight change in the design of class-
> based views. It is similar in purpose to the existing ones, but much
> simpler to use and to extend.
>
> Examples speak louder than words:
>
> --- urls.py ---
>
> urlpatterns = patterns('',
>     url(r'^(\d)+/$', views.Article),
> )
>
> --- views.py ---
>
> @login_required
> class Article(View):
>
>     def __init__(self, request, pk):
>         super(Article, self).__init__(request, pk)
>         self.pk = pk
>
>     def get(self):
>         article = get_object_or_404(Article, pk=self.pk)
>         return render_to_response('hello.html', {'article': article})
>
>     def post(self):
>         return HttpResponse('You posted something but I threw it
> away.')
>
> ---
>
> Points of note:
>  - the usage in urls.py is now indistinguishable from regular views;
>  - subclasses may extend __init__ to make use of request parameters;
>  - the dispatch logic, based on http method, is hidden in the base
> class;
>  - standard decorators may be simply applied to the class (Python >=
> 2.6)
>
> Here is the View base class:http://dpaste.com/hold/665528/
> It's very simple, even shorter than the existing implementation.
>
> I haven't taken the time to translate the whole django.views.generic
> package to this new design, but I will do so shortly, assuming I get
> some kind of positive feedback. The existing functionality (the
> various generic views and mixins) should be fairly easy to port to the
> new design.
>
> This is a slightly different design, so there are bound to be a few
> incompatibilities. For example in my code the dispatched methods (get,
> post...) don't receive the request object and parameters, because they
> were already passed to __init__ and it wouldn't make sense to pass
> them again.
>
> I'm not familiar with Django practices about backwards compatibility.
> If it's really important not to break old code, I guess the new style
> classes could be made to keep the same interface as existing ones,
> including a dummy as_view() method. But it would pollute the code with
> old cruft. Or they could be implemented in a new package. I need
> further directions on this issue.
>
> -Tobia

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: slow function

2011-12-05 Thread huseyin yilmaz
With select related, hole queries can be ommitted but this time for
every score object one hole object will be created. so there will be
alot of hole objects.

On Dec 5, 12:18 pm, Håkon Erichsen  wrote:
> 2011/12/5 kenneth gonsalves 
>
> >  The code looks simple to me, but to analyse 10,000 rounds of golf
> > (1,80,000 hole scores) my 2 GB laptop takes 20 minutes. Would this be
> > considered normal - or slow? If slow, ideas on how to speed it up would be
> > appreciated.
>
> One thing you should look into is 
> QuerySet.select_related():https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-re...
>
> Without it, every time you run scr.hole on a new scr, Django will run a new
> query, fetching that 'hole' object. If you have 10 000 scores, that means
> 10 000 queries, which is an insane number for queries like this. If you use
> select_related, Django will fetch the corrosponding hole for you, in the
> same query... meaning 1 query, instead of 10 000 :)
>
> In other words, change this:
>
>     scrs = Score.objects.all()    pscrs =
> Pscore.objects.filter(hole__tee__course = club)
>
> To this:
>
>     scrs = Score.objects.all().select_related('hole')    pscrs =
> Pscore.objects.filter(hole__tee__course = club).select_related('hole')
>
> That seems to be the biggest problem you have. Some other comments:
>
> - Holy mother of god, that's a huge view file! I would advice to slice
> it into logically separated files, and put this in a directory called
> "views", everything doesn't have to be in views.py!
>
> - Put your forms in another file, like forms.py
>
> - If you're just checking if someone is logged in with
> @user_passes_test, why not just use @login_required?
>
> - Check out 
> render:https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render
>
> Best regards,
>
> Håkon Erichsen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: slow function

2011-12-05 Thread huseyin yilmaz
First of all You are queryin everything that you have on database for
this view and making django model objects from those. For a large db
this will run very slow and for larger dbs, it will throw memmory
exception.
Try something like this:
for hole in Hole.objects.filter(tee_course=club):
...
for score in Score.objects.filter(hole = hole)
   
for pscore in PScore.objects.filter(hole=hole)
   


With this setup you will get your memmory footprint alot smaller. and
it will run alot faster that way. and you will get rid of queries that
come from score.hole as well .

You can use values_list method to get even faster code.

Note : for more tips http://goo.gl/TMnPc
On Dec 5, 11:56 am, kenneth gonsalves  wrote:
> I have a function called holediff - the code is here:
>
> https://bitbucket.org/lawgon/djangogolf/src/a86c388f1795/web/views.py... analyses
>  golf scores and calculates the relative difficulty of the holes. The code 
> looks simple to me, but to analyse 10,000 rounds of golf (1,80,000 hole 
> scores) my 2 GB laptop takes 20 minutes. Would this be considered normal - or 
> slow? If slow, ideas on how to speed it up would be appreciated.
> --
> regards
> Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: slow function

2011-12-05 Thread Brian Schott
That's usually a bad sign when other programmers start naming saints when 
reviewing your code :-).   I have similar code explosion issues in a models.py 
file in a site I'm building.  

What's the best dangothonic way to break up models.py or views.py for that 
matter.  
1. Create a models.py or views.py at the top level that does a bunch of 
imports?  Explicitly or progrmmatically by looping over files?
2. Expose the hierarchy to the caller.  Ex: from my_app.models.my_model import 
MyModel
3. Break up the whole app into smaller apps?  

Still trying to figure out a good way to determine what should be a separate 
app.  If you have a relathionships like Publishers -> Books, and Authors -> 
Books should you try to break out Books, Authors, and Publishers as separate 
apps?  

Brian Schott
bfsch...@gmail.com



On Dec 5, 2011, at 5:18 AM, Håkon Erichsen wrote:

> - Holy mother of god, that's a huge view file! I would advice to slice it 
> into logically separated files, and put this in a directory called "views", 
> everything doesn't have to be in views.py!
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: deleting my old messages

2011-12-05 Thread Russell Keith-Magee
On Sat, Dec 3, 2011 at 4:39 AM, gintare  wrote:
> Hello,
>
> Could you please delete all my posts. I look through them and copied
> all needed information. I am not able to find the new questions among
> old messages. After deletion the search with my name as a keyword will
> give me the latest questions.

I'm afraid we're not going to delete messages from an archive. The
reason we have an archive is so that when someone asks a question that
has been asked before, we can point them at an existing answer.
Deleting old questions would defeat that goal.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to format string on I18n

2011-12-05 Thread Tsung-Hsien
Thank you!
the default character of MySQL does not utf-8, so after altering the
character, the message can show on the page.
However, the message shows only English, except I don't use the %
(email)s.
I have been delete the "#, fuzzy" and remain the "#, python-format",
but the string still show English.

How to solve this?
thanks!!



On Dec 4, 10:45 pm, Mimi Tantono  wrote:
> Please look at the thread 
> below:http://stackoverflow.com/questions/873419/converting-to-safe-unicode-...
>
> And you would want to make sure that database encoding style is already set
> to UTF-8 (if applicable).
>
> 2011/12/5 Tsung-Hsien 
>
>
>
>
>
>
>
>
>
> > Hello
> >I get the wrong message when type a string which needed to format
> > such as
>
> > msgid "An inviatation was sent to %(email)s."
> > msgstr "邀請已送到%(email)s"
>
> > --- 
> > ---
> > Incorrect string value: '\xE9\x82\x80\xE8\xAB\x8B...' for column
> > 'message' at row 1
>
> > --- 
> > ---
> > How to fix it?
> > Thanks!!
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.> To post to this group, send email 
> > todjango-us...@googlegroups.com.
> > To unsubscribe from this group, send email 
> > to>django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
>
> Best Regards,
>
> Mimi Tantono 
>
> *It is always hard to do new things, and it should be getting even harder
> along the time because then it indicates that we are improving.*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Bulk import of data

2011-12-05 Thread Tom Evans
On Sun, Dec 4, 2011 at 2:53 AM, Karen Tracey  wrote:
> On Sat, Dec 3, 2011 at 9:37 PM, Nathan McCorkle  wrote:
>>
>> when you say 'as long as you don't use the ORM for inserts',
>
>
> You do not want to be building and saving objects individually with the ORM.
> You want to be using some form of bulk insert. Django 1.4 will add bulk
> create capability (see
> https://docs.djangoproject.com/en/dev/ref/models/querysets/#bulk-create).
> Prior to 1.4 you can use the development trunk level code, or you can find
> other libraries that provide bulk insert (see for example
> http://ole-laursen.blogspot.com/2010/11/bulk-inserting-django-objects.html).
> http://www.caktusgroup.com/blog/2011/09/20/bulk-inserts-django/ mentions the
> kinds of speedups you can expect with using a bulk insert technique vs.
> creating objects individually with the ORM.
>
> Karen

OTOH, if (like the OP) you have a few small (<1k) CSV files to import,
then going through the ORM is easy, simple and quick to code. The fact
that you can get it to run 1 minute quicker by not using the ORM is
not relevant, unless importing CSV files is the main task of your
server, and it will be doing it 24x7.

Premature optimization is the root of all evil.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: slow function

2011-12-05 Thread Håkon Erichsen
2011/12/5 kenneth gonsalves 

>  The code looks simple to me, but to analyse 10,000 rounds of golf
> (1,80,000 hole scores) my 2 GB laptop takes 20 minutes. Would this be
> considered normal - or slow? If slow, ideas on how to speed it up would be
> appreciated.
>
>
One thing you should look into is QuerySet.select_related():
https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related

Without it, every time you run scr.hole on a new scr, Django will run a new
query, fetching that 'hole' object. If you have 10 000 scores, that means
10 000 queries, which is an insane number for queries like this. If you use
select_related, Django will fetch the corrosponding hole for you, in the
same query... meaning 1 query, instead of 10 000 :)

In other words, change this:


scrs = Score.objects.all()pscrs =
Pscore.objects.filter(hole__tee__course = club)


To this:


scrs = Score.objects.all().select_related('hole')pscrs =
Pscore.objects.filter(hole__tee__course = club).select_related('hole')


That seems to be the biggest problem you have. Some other comments:

- Holy mother of god, that's a huge view file! I would advice to slice
it into logically separated files, and put this in a directory called
"views", everything doesn't have to be in views.py!

- Put your forms in another file, like forms.py

- If you're just checking if someone is logged in with
@user_passes_test, why not just use @login_required?

- Check out render:
https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render


Best regards,

Håkon Erichsen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to format string on I18n

2011-12-05 Thread Mimi Tantono
Please look at the thread below:
http://stackoverflow.com/questions/873419/converting-to-safe-unicode-in-python

And you would want to make sure that database encoding style is already set
to UTF-8 (if applicable).

2011/12/5 Tsung-Hsien 

> Hello
>I get the wrong message when type a string which needed to format
> such as
>
> msgid "An inviatation was sent to %(email)s."
> msgstr "邀請已送到%(email)s"
>
>
> --
> Incorrect string value: '\xE9\x82\x80\xE8\xAB\x8B...' for column
> 'message' at row 1
>
> --
> How to fix it?
> Thanks!!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 


Best Regards,

Mimi Tantono 

*It is always hard to do new things, and it should be getting even harder
along the time because then it indicates that we are improving.*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



AW: Performance

2011-12-05 Thread Szabo, Patrick (LNG-VIE)
Okay that toolbar is really useful and also looks kind of nice
J...Thanks for that. 

I've already found the problemsomehow my app triggers 800 queries
just for a simple page.

Can I somehow find out which part of my code is causing those queries ?!

 

patrick

 

Von: django-users@googlegroups.com
[mailto:django-users@googlegroups.com] Im Auftrag von Nikolas
Stevenson-Molnar
Gesendet: Montag, 05. Dezember 2011 08:14
An: Nikolas Stevenson-Molnar
Cc: django-users@googlegroups.com
Betreff: Re: Performance

 

A bit more searching turned up something even better... looks like the
Django folks address this directly:
https://code.djangoproject.com/wiki/ProfilingDjango

 

_Nik

 

On Dec 4, 2011, at 11:03 PM, Nikolas Stevenson-Molnar wrote:





I haven't done this myself, but I would assume you could use the Python
profiler. Here's one project that facilitates profiling a WSGI app
(assuming you're using Django via WSGI): http://repoze.org/

 

Others here may have more experience with profiling web apps.

 

_Nik

 

On Dec 4, 2011, at 10:55 PM, Szabo, Patrick (LNG-VIE) wrote:





Hi,

 

In the last couple of weeks my app has become quite slowly and I'm
wondering why that is.

Are there any debugging tools where I can see what takes how much time ?

 

cheers

 

. . . . . . . . . . . . . . . . . . . . . . . . . .

Ing. Patrick Szabo
XSLT Developer

LexisNexis
Marxergasse 25, 1030 Wien

patrick.sz...@lexisnexis.at

Tel.: 00431 534521573

Fax: +43 (1) 534 52 - 146

 

 

 

-- 
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.

 

 

-- 
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.


. . . . . . . . . . . . . . . . . . . . . . . . . .
Ing. Patrick Szabo
 XSLT Developer 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick.sz...@lexisnexis.at
Tel.: 00431 534521573 
Fax: +43 (1) 534 52 - 146 





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: slow function

2011-12-05 Thread kenneth gonsalves
On Mon, 2011-12-05 at 11:36 +0100, Masklinn wrote:
> >
> https://bitbucket.org/lawgon/djangogolf/src/a86c388f1795/web/views.py#cl-372  
> analyses golf scores and calculates the relative difficulty of the holes. The 
> code looks simple to me, but to analyse 10,000 rounds of golf (1,80,000 hole 
> scores) my 2 GB laptop takes 20 minutes. Would this be considered normal - or 
> slow? If slow, ideas on how to speed it up would be appreciated.
> It certainly does not seem fast, but I don't think it's possible to
> psychically debug that stuff, so you'll need to collect stats on which
> section of the function takes time:
> 
> * The first half looks like straightforward numerical code (three
> iterations on three straightforward-looking querysets back-to-back,
> but not nested), while Python is not the fastest language at numerical
> stuff, even CPython "only" takes ~100ms for 2 million additions (on a
> 2.4GHz Core i5)

this is what takes the time
> * The gviz_api work could be more expensive (CPU-wise) than the simple
> calls let think

takes a few seconds 
> * Depending on the amount of data generated, the issue could also come
> from rendering the data 

the amount of data generated is minimal - 18 sets of data containing one
string and 2 numbers each.
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: slow function

2011-12-05 Thread Masklinn
On 2011-12-05, at 10:56 , kenneth gonsalves wrote:
> I have a function called holediff - the code is here:
> 
> https://bitbucket.org/lawgon/djangogolf/src/a86c388f1795/web/views.py#cl-372  
> analyses golf scores and calculates the relative difficulty of the holes. The 
> code looks simple to me, but to analyse 10,000 rounds of golf (1,80,000 hole 
> scores) my 2 GB laptop takes 20 minutes. Would this be considered normal - or 
> slow? If slow, ideas on how to speed it up would be appreciated.
It certainly does not seem fast, but I don't think it's possible to psychically 
debug that stuff, so you'll need to collect stats on which section of the 
function takes time:

* The first half looks like straightforward numerical code (three iterations on 
three straightforward-looking querysets back-to-back, but not nested), while 
Python is not the fastest language at numerical stuff, even CPython "only" 
takes ~100ms for 2 million additions (on a 2.4GHz Core i5)
* The gviz_api work could be more expensive (CPU-wise) than the simple calls 
let think
* Depending on the amount of data generated, the issue could also come from 
rendering the data

But without measurements and knowing which part of the function actually burns 
those 20 minutes…

(as a first approximation, and if the gviz stuff runs on it, you could try 
running the function on Pypy, if it's the numerical section which slows it 
down, pypy should be able to make short of it).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



slow function

2011-12-05 Thread kenneth gonsalves
I have a function called holediff - the code is here:

https://bitbucket.org/lawgon/djangogolf/src/a86c388f1795/web/views.py#cl-372  
analyses golf scores and calculates the relative difficulty of the holes. The 
code looks simple to me, but to analyse 10,000 rounds of golf (1,80,000 hole 
scores) my 2 GB laptop takes 20 minutes. Would this be considered normal - or 
slow? If slow, ideas on how to speed it up would be appreciated.
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



AW: Performance

2011-12-05 Thread Szabo, Patrick (LNG-VIE)
Thx a lot i will check this out !

 

Von: django-users@googlegroups.com
[mailto:django-users@googlegroups.com] Im Auftrag von Nikolas
Stevenson-Molnar
Gesendet: Montag, 05. Dezember 2011 08:14
An: Nikolas Stevenson-Molnar
Cc: django-users@googlegroups.com
Betreff: Re: Performance

 

A bit more searching turned up something even better... looks like the
Django folks address this directly:
https://code.djangoproject.com/wiki/ProfilingDjango

 

_Nik

 

On Dec 4, 2011, at 11:03 PM, Nikolas Stevenson-Molnar wrote:





I haven't done this myself, but I would assume you could use the Python
profiler. Here's one project that facilitates profiling a WSGI app
(assuming you're using Django via WSGI): http://repoze.org/

 

Others here may have more experience with profiling web apps.

 

_Nik

 

On Dec 4, 2011, at 10:55 PM, Szabo, Patrick (LNG-VIE) wrote:





Hi,

 

In the last couple of weeks my app has become quite slowly and I'm
wondering why that is.

Are there any debugging tools where I can see what takes how much time ?

 

cheers

 

. . . . . . . . . . . . . . . . . . . . . . . . . .

Ing. Patrick Szabo
XSLT Developer

LexisNexis
Marxergasse 25, 1030 Wien

patrick.sz...@lexisnexis.at

Tel.: 00431 534521573

Fax: +43 (1) 534 52 - 146

 

 

 

-- 
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.

 

 

-- 
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.


. . . . . . . . . . . . . . . . . . . . . . . . . .
Ing. Patrick Szabo
 XSLT Developer 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick.sz...@lexisnexis.at
Tel.: 00431 534521573 
Fax: +43 (1) 534 52 - 146 





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.