我正在尝试在manytomany字段中使用自定义搜索选项来管理面板。它不起作用。搜索后我想将所选项目显示为搜索字段下方的列表,目前它在搜索字段中显示逗号分隔值。这是我的代码
class MyModel(models.Model):
my_data= models.ManyToManyField(Topic, blank=True, null=True, related_name='mymodel_data')
admin.py
class MyModelCustom(admin.ModelAdmin):
model = MyModel
# define the raw_id_fields
raw_id_fields = ('my_data',)
# define the related_lookup_fields
related_lookup_fields = {
'my_data': ['my_data']
}
admin.site.register(MyModel, MyModelCustom)
请帮助
答案 0 :(得分:0)
ModelAdmin中的related_lookup_fields错误。它必须是:
related_lookup_fields = {
'm2m' : ['my_data']
}