Friday, August 1, 2014

Problem with limit_choices_to and filtering foreign key

I have two models, ReqForChange(models.Model) and RfcStatus(models.Model).

class ReqForChange(models.Model):
rfc = models.AutoField (primary_key=True)
       user = models.ForeignKey(User, verbose_name="Requested by")
      status = models.ForeignKey(Status, verbose_name="RfC State")
       effectOnUsers = models.NullBooleanField("Effect", blank=True, null=True)



class RfcStatus(models.Model):
rfcd = models.AutoField (primary_key=True)
rfcStatusDateCreated = models.DateField("Created date", default=datetime.now())
rfc_details = models.ForeignKey(ReqForChange, limit_choices_to={'effectOnUsers': True}, blank=True, null=True)


In my admin page I want the user to register a new ReqForChange  and when the user open the RfcStatus the dropdown menu for the field effectOnUsers shall only display items where effectOnUsers is set to True. This do not work and I can't understand why? I have tried the limit_choice_to on the User field in the ReqForChange model, and that works fine.

I hope someone can give me a hint on how I can manage to filter values for my rfc_details field. I run django 1.6

Best regards,

Hilde T L Rafaelsen

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/24dee8af-5686-45db-af1b-26fa17d91125%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment