ScottB schreef: > I think you need to pass the actual values (i.e. the rooms), rather > than a function that returns them. Also 'id_in' needs two > underscores. So maybe: > > limit_choices_to = {'id__in': get_rooms()} > > Scott
Indeed, i had already found out there was an underscore short. I tried 'id__in': get_rooms() and that won't work as it doesn't know Patient when the function is called. That's why you have to use get_rooms instead of get_rooms. The error is "global name 'Patient' is not defined". So it seems like this method is not going to work after all. Are there any other ways to get a limited list (keeping in mind i'm not using newforms) for a ForeignKey field? I tried using this in my view: room_choices = [(room.id, str(room)) for room in Room.objects.filter() ] room_choices.sort() room_choices.insert(0,BLANK_CHOICE_DASH[0]) # [('','---------')] Since i don't want to redesign the whole form, i change the current field entry. I first look up the index of the field: index = 0 for field in fields: if ( field.field_name == "room" ): break index+=1 return index Then i replace that index with my version: fields[index] = forms.SelectField(field_name="room", choices = room_choices) Which indeed gives me a limited list but when you change the data of a patient, the room he's in isn't selected. This something i still need to change as the query leaves out the room/bed of the currently selected patient too. But even when i just select all rooms, the room the patient is in isn't selected. Any idea how you can "select" a choice in the formfield? Or any less cumbersome method to limit the choices? Thanks, Benedict --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---