class TrialRun(models.Model):
product = models.ForeignKey(NewProduct, verbose_name='Product',)
class Component(models.Model):
product = models.ForeignKey(NewProduct, verbose_name='Product',)
class TrialIssue(models.Model):
trialrun = models.ForeignKey(TrialRun, verbose_name='Trial Run',)
components = models.ManyToManyField(
Component,limit_choices_to{product=trialrun.product})
How could I realize the thinking of (Component, limit_choices_to={product=trialrun.product})
?
i can not use the following
def __init__(self, *args, **kwargs):
super(TrialIssueForm, self).__init__(*args, **kwargs)
# make sure we're editing a saved model
if self.instance.id:
self.fields['components'].queryset = Component.objects.filter(product=self.instance.trialrun.product)