所以我试图过滤内联形式中的字段。我跟着this SO example课程和Strand正在过滤到课程,但概念不会过滤并返回所有记录。
if db_field.name == 'course':
kwargs['queryset'] = Course.objects.filter(pk = course_id)
elif db_field.name == 'strand':
kwargs['queryset'] = Strand.objects.filter(course = course_id)
elif db_field.name == 'concepts':
kwargs['queryset'] = Concept.objects.filter(course__id = course_id)
我正在使用的模型是:
class Indicator (models.Model):
id = models.AutoField(primary_key=True) # AutoField?
code = models.CharField(max_length=10)
indicator_text = models.TextField(blank=True)
explained = models.TextField("Explained",blank=True)
course = models.ForeignKey('curriculum.Course')
theme = models.ForeignKey(Theme)
strand = models.ForeignKey(Strand,blank=True,null=True)
level = models.ForeignKey(Level,blank=True,null=True)
concepts = models.ManyToManyField(Concept,blank=True)
class Course (models.Model):
id = models.AutoField(primary_key=True) # AutoField?
course_text = models.CharField(max_length=100, unique=True)
slug = models.CharField(max_length=100)
subject = models.ForeignKey(Subject)
excerpt = models.CharField(max_length=255, unique=True)
description = models.TextField(blank=True)
zorder = models.IntegerField(default=0)
license = models.TextField("License", blank=True, null=True)
icon = models.ImageField("Icon",upload_to='icons/',blank=True,null=True)
class Theme (models.Model):
id = models.AutoField(primary_key=True) # AutoField?
code = models.CharField(max_length=5)
course = models.ForeignKey(Course)
theme_text = models.CharField(max_length=50)
description = models.TextField(blank=True, max_length=1000)
zorder = models.IntegerField()
class Strand (models.Model):
id = models.AutoField(primary_key=True) # AutoField?
code = models.CharField(max_length=3)
course = models.ForeignKey(Course)
strand_text = models.CharField(max_length=50)
description = models.TextField(blank=True, max_length=1000)
class Concept (models.Model):
id = models.AutoField(primary_key=True) # AutoField?
code = models.CharField(max_length=3)
course = models.ForeignKey(Course)
concept_text = models.CharField(max_length=50)
description = models.TextField(blank=True, max_length=255)
这是一个已知问题还是我想要做的事情的怪癖?
一如既往地感谢您的帮助。
克里斯