On Apr 16, 7:29 pm, Aljoša Mohorović <aljosa.mohoro...@gmail.com> wrote: > if i have something like this: > ======= > class MyModel(models.Model): > name = models.CharField(max_length=255) > > class OtherModel(models.Model): > name = models.CharField(max_length=255) > mymodel = models.ForeignKey(MyModel) > > class MyModelItem(models.Model): > mymodel = models.ForeignKey(MyModel) > other = models.ForeignKey(OtherModel, null=True, blank=True) > ======= > > how can i use limit_choices_to (or some other way) to filter > ForeignKey choices based on current model field? > basically, how can i do: > other = models.ForeignKey(OtherModel, null=True, blank=True, > limit_choices_to={'mymodel': 'self.mymodel'}) > > any options works for me (overwriting admin.TabularInline or form for > TabularInline). > thanks for any info.
Have a look at: http://stackoverflow.com/questions/1387431/django-model-modelform-how-to-get-dynamic-choices-in-choicefield or http://stackoverflow.com/questions/3419997/creating-a-dynamic-choice-field If you want to change a live form where items in combobox B depend on an item selected in combobox A, then you will need to use custom javascript (and there are a ton of examples on the web using, for example, jQuery). -- 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.