On Tue, 2006-08-01 at 15:27 +0000, Jakub 'teodor' Krajniak wrote:
> Hi there,
>
> I've looked for some clue on this group but nothing similar for my
> case.
> I've got the following models:
>
> class Service:
> name =
> ...
> class TimeTable:
> ...
>
> class UserService:
> user = ForeignKey(User)
> service = ForeignKey(Service)
> timetable = ForeignKey(TimeTable)
>
> I've tried to get list of service that aren't used by selected user, in
> this way:
> cursor.execute("SELECT sms_service.name FROM sms_service WHERE
> sms_service.id NOT IN (SELECT sms_userservices.service_id FROM
> sms_userservices WHERE sms_userservices.user_id = 9)"),
> it's in dirty sql. I was trying use filter and exclude, but didn't get
> correct results.
> Service.objects.exclude(userservices__user__id=9)
> return empty list, I'm sure that I've some service that aren't used by
> this user. I don't know
> why that didn't work for me, so could sombody show me how to rewrite
> this piece of sql code into django right way?
Anything that requires a nested select in SQL does not have a direct
equivalent in the Django query interface at the moment.
However, if we ignore the SQL for a moment and think about the Python
code, it is a reasonable construction to write. There is some work going
on under the covers at the moment to fix a few problems with the way we
convert Python code into SQL queries and exclude() has more than its
share of corner cases there. So it's possible that in the short- to
medium-term, this will be fixed to work "naturally". In the meantime,
custom SQL is your friend.
Regards,
Malcolm
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---