* Benedict Verheyen wrote, On 12.02.2007 12:03:
> Benedict Verheyen schreef:
> <snip>
> 
> I almost succeeded in getting there.
> I can get the rooms i want via this command:
> 
> r = models.ForeignKey(Room, blank=True, null=True, limit_choices_to =
> Room.objects.exclude(id__in=[patient.room.id for patient in
> Patient.objects.filter(room__isnull=False)]) )
> 
> However, this produces an error when i put it in my Patient model:
> class Patient(models.Model):
>     ...
>     room = models.ForeignKey(Room, blank=True, null=True,
>     limit_choices_to = Room.objects.exclude(id__in=[patient.room.id for
>               patient in Patient.objects.filter(room__isnull=False)]) )
>     ...
> 
> The error when i access the page is "name 'Patient' is not defined"
> 
> Any idea how i can take this last hurdle?

You can't use the limit_choices_to like this because it will only be executed 
at the import time and also Patient class 
is not yet defined. You'll probably want something like this:

def get_rooms():
        return Room.objects.exclude(id__in=[patient.room.id for patient in 
Patient.objects.filter(room__isnull=False)]))
[...]
class Patient(models.Model):
        [...]
                limit_choices_to = get_rooms # no ()

-- 
Nebojša Đorđević - nesh, ICQ#43799892
Studio Quattro - Niš - Serbia
http://studioquattro.biz/ | http://trac.studioquattro.biz/djangoutils/
Registered Linux User 282159 [http://counter.li.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to