Re: How do I manually set the "GROUP BY" for a django queryset?

2010-02-15 Thread Greg Brown
That's a good point, but then the ird_number field (on UserProfile) is
inaccessible. I'd need to do something like

User.objects.values('first_name', 'last_name', 'pk',
'userprofile__ird_number').annotate(
   Max('application__creation_date'),
).order_by('-application__creation_date__max').select_related()

but that raises

FieldError: Invalid field name: 'userprofile__ird_number'

Greg




On 16 February 2010 10:13, Dj Gilcrease <digitalx...@gmail.com> wrote:
> On Mon, Feb 15, 2010 at 1:43 PM, Greg Brown <gregplaysgui...@gmail.com> wrote:
>> The queryset giving the problem is
>>
>> UserProfile.objects.values(
>>        'ird_number', 'user__first_name', 'user__last_name', 'user__pk',
>>    ).annotate(
>>        Max('user__application__creation_date'),
>>    ).order_by('-user__application__creation_date__max')
>
>
> It looks to me like you are trying to get more info from the User
> model then then UserProfile model, so maybe change your query to be
> based on the User not the UserProfile
>
>
> User.objects.values('first_name', 'last_name', 'pk').annotate(
>    Max('application__creation_date'),
> ).order_by('-application__creation_date__max').select_related()
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-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.
>
>



-- 
http://gregbrown.co.nz/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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.



Re: How do I manually set the "GROUP BY" for a django queryset?

2010-02-15 Thread Greg Brown
Ok, here goes:

First, some background - UserProfile is the
settings.AUTH_PROFILE_MODULE and the Application model has a
ForeignKey to User. There's ~90,000 users/userprofiles, ~110,000
applications (most have only one application, some have 2). The
database is mysql. If that's not enough info, let me know and I'll see
if I can put together a simple reproduce-able test case.

The queryset giving the problem is

UserProfile.objects.values(
'ird_number', 'user__first_name', 'user__last_name', 'user__pk',
).annotate(
Max('user__application__creation_date'),
).order_by('-user__application__creation_date__max')

I'm beginning to think it might be a bug - because UserProfile and
User are joined by a one-to-one relationship, it's sufficient to group
by one of their primary keys, and I think the ORM should know this.

Should I open a ticket for this?

Greg




On 15 February 2010 13:07, Russell Keith-Magee  wrote:
> On Mon, Feb 15, 2010 at 6:30 AM, Greg  wrote:
>> I have a large-ish query which is taking ~10 seconds to run, but I can
>> get it down to less than a second by changing the group by part of the
>> query from
>>
>>    GROUP BY `refunds_userprofile`.`ird_number` ,
>> `auth_user`.`first_name` , `auth_user`.`last_name` ,
>> `refunds_userprofile`.`user_id` , `auth_user`.`id` ,
>> `auth_user`.`username` , `auth_user`.`first_name` ,
>> `auth_user`.`last_name` , `auth_user`.`email` ,
>> `auth_user`.`password` , `auth_user`.`is_staff` ,
>> `auth_user`.`is_active` , `auth_user`.`is_superuser` ,
>> `auth_user`.`last_login` , `auth_user`.`date_joined`
>>
>> to
>>
>>    GROUP BY `refunds_userprofile`.`ird_number`
>>
>> (note this doesn't change the query results)
>>
>> I figured I might have to use some undocumented methods to do this,
>> but I couldn't figure it out - I've tried explicitly setting the
>> query.group_by attribute with no success. Does anyone know how I could
>> do this?
>
> The short answer is  "you don't". Django doesn't expose any way to
> manually control GROUP BY because that is a relational construct, and
> Django is attempting to provide an Object-like wrapper.
>
> As for why dropping GROUP BY clauses is faster - remember, t's always
> possible to get the wrong answer in O(1) time :-) Daniel has asked the
> more important question - what are you trying to do? Django is
> generally pretty careful about adding GROUP BY clauses; arbitrarily
> dropping them make me a little nervous. It's possible you're found a
> bug, but it's impossible to confirm that without more details.
>
> 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-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.
>
>



-- 
http://gregbrown.co.nz/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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.



Re: Help about models

2009-11-08 Thread Greg Brown

What you need is to keep your Education model as is (with no Lawyer
Foreignkey) and add a ManyToManyField on your Lawyer class pointing to
Education. Then you can go

Lawyer.objects.filter(education__school='...')

I think that will solve your problem

Greg



2009/11/9 Zeynel :
>
> Hello,
>
> I decided to start my own project with what I learned from part 1 of
> the tutorial.
>
> I have the project in C:\sw\sw\wkw
>
> The app sw.wkw is a prototype for a "who-knows-who" database for legal
> profession. I wanted to start with a really simple model:
>
> class Lawyer(models.Model):
>    first = models.CharField(max_length=20)
>    initial = models.CharField(max_length=2)
>    last = models.CharField(max_length=20)
>    year_graduated = models.DateTimeField('Year graduated')
>
> class Education(models.Model):
> #    lawyer = models.ForeignKey(lawyer)
>    school = models.CharField(max_length=200)
>
> I commented out the ForeignKey because it caused an error.
>
> I will only make one search in the database. I want to enter Lawyer's
> name and find all other lawyers in the database who graduated from the
> same school the same year. It's like sorting by school in a
> spreadsheet and pulling the lawyer's names. Here's the sample
> spreadsheet:
>
> https://spreadsheets.google.com/ccc?key=0Al923jWh4O4ydG1vSmx4bDVqTUFUXzVqSXhzVkcydmc=en
>
> Do you think this is the right model for what I am trying to do? Thank
> you for your comments.
>
> So far I created the tables and tomorrow I'll set up the admin and
> populate the database with some names.
>
> I am really enjoying Django. I am learning both Django and Python.
> Thanks again for your help.
> >
>



-- 
http://gregbrown.co.nz/

--~--~-~--~~~---~--~~
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: Django admin stops showing all apps

2009-11-04 Thread Greg Brown

Hi Diego,

Thanks for your suggestion - I had looked in the logs but not hard
enough it would seem!

I think I've tracked the problem down... for some reason my models.py
files sometimes can't complete an import (this was in the logs, I have
no idea why it fails however) and because of this, the model doesn't
show up in the admin homepage. The related content still shows in the
front end of the site though. I'm a bit confused, but I've refactored
the code so the offending import isn't required, and so far so good.

Greg



2009/11/5 Diego Ucha :
>
> Hello Greg,
>
> What does Apache writes in his log when you try to access the admin
> when it is unreachable?
>
> []s,
> Diego Ucha
> http://www.scientificcircle.com/
>
> On 1 nov, 20:52, Greg  wrote:
>> Hi all,
>>
>> I have a very strange problem with one of my django sites - when I
>> start apache, everything works fine, but after a while, all of my site-
>> specific apps will stop showing in the admin site. Library apps and
>> django's built in apps are still there. Does anyone have any ideas as
>> to why this might happen?
>>
>> It seems like a path issue, but I have no idea why it works at the
>> start and then dies for no apparent reason down the track.
>>
>> I'm running it via mod_wsgi, on webfaction. In my wsgi file, I'm
>> setting the python path like so:
>>
>>
>>
>> > import os
>> > import sys
>>
>> > for directory in [
>> >     '/PATH/django',
>> >     '/PATH/django/library',
>> >     '/PATH/django/nzmusic',
>> >     '/PATH/django/lib'
>> > ]:
>> >     if not directory in sys.path:
>> >         sys.path.insert(0, directory)
>>
>> > from django.core.handlers.wsgi import WSGIHandler
>>
>> > os.environ['DJANGO_SETTINGS_MODULE'] = 'nzmusic.settings'
>> > os.environ['LD_LIBRARY_PATH'] = '/PATH/lib'
>> > application = WSGIHandler()
>>
>> Thanks,
>> Greg
> >
>



-- 
http://gregbrown.co.nz/

--~--~-~--~~~---~--~~
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: Django Project Management App

2009-09-13 Thread Greg Brown

Cheers for the feedback folks. Just to be clear, my app doesn't handle
code repositories or bug tracking at all - it's very much a one-user
system at the moment. I actually just run it on my Macbook in a
terminal (applescripted on startup). It's somewhat similar to basecamp
I guess, albeit much simpler - per-project todo lists, time tracking,
and invoice generation are pretty much all it can do for now.

Anyway, once I've found some time to clean it up, I'll unleash it on
the world and see what happens...

Cheers,
Greg



2009/9/11 Thomas Guettler :
>
> Greg schrieb:
>> Hi all,
>>
>> Since I started with django a year or so ago, I've been gradually
>> building a very simple project management app for myself - it started
>> as a project to learn the language but has evolved into a very useful
>> tool, handling all my timetracking, task management and invoicing.
>>
>> I'm wondering if it would be worth open sourcing it?
>
> Of course, do it.
>
>> Right now it's
>> very much set up for me and me only, but it wouldn't take too much
>> effort to make it a portable app that others could use. I've looked
>> for django project management projects to use and/or contribute to,
>> but there doesn't seem to be any out there.
>>
>
> There is one. I searched for an alternative to trac some time ago. Basie
> can handle several SVN-Repositories (Trac does not) and uses django.
>
> But I had to time to try it:
>
>   http://basieproject.org/
>
>  Thomas
>
>
> --
> Thomas Guettler, http://www.thomas-guettler.de/
> E-Mail: guettli (*) thomas-guettler + de
>
> >
>



-- 
http://gregbrown.co.nz/

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---