我想在内联中过滤我的选择。
模型:
class Prob(models.Model):
project = models.ForeignKey(Project)
...
我得到了admin.py,如:
class MaterialInline(admin.StackedInline):
model = Material
def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
if db_field.name == 'material':
kwargs['queryset'] = Material.objects.filter(project = request.???)
class ProbAdmin(admin.ModelAdmin):
inlines = [MaterialInline,]
“请求。???”是我的问题。我不知道如何访问项目。我尝试了类似request.GET.get('id_material__selected')的内容,因为下拉列表名为id_material。但它没有用。
提前致谢!