0
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})
的想法?ManyToManyField限制选择动态外国模式
我不能使用以下
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)
嗨,我使用一个在我的问题,但没有效果 – user687673
您好,我无法找到为许多人提供一种方式,你能帮助更清楚吗? – user687673
它也非常喜欢在stackoverflow.com/questions/19726274/django-models-limit-manytomanyfield-to-owner的unresoved问题 – user687673