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})
我怎么能体会到的思想(Component, limit_choices_to={product=trialrun.product})
?
我不能使用以下
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)