问题描述
我遇到了一个典型的问题,我在一个模型中有一个ListField。
I've ran into a typical problem where I have a ListField in a model.
我想使用Django管理员玩对象并且ListField并不那么重要,它是我可以没有的嵌入式对象的列表。
I'd like to use the Django admin to play around with the object and the ListField isn't that crucial, it's a list of embedded objects that I can live without.
当我使用这个,我得到主管理页面上的错误。如果在注册原始Item对象时不使用ModelAdmin对象,则只有在尝试添加项目时才会收到错误。
When I use this, I get the error on the main admin page. If I don't use the ModelAdmin object when registering the original Item object, I only get the error if I try to add an Item.
from django.contrib import admin
class ItemAdmin(admin.ModelAdmin):
exclude = ('bids',)
admin.site.register(Item, ItemAdmin)
如何正确排除出价ListField? b $ b
How to properly exclude the "bids" ListField then?
推荐答案
我通过使我的ListField无法编辑,因为我无法获得排除
为我工作..
I worked round it by making my ListField non editable, as I couldnt get exclude
to work for me either..
例如:
class Item(models.Model):
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
title = models.CharField(max_length=255)
bids = ListField(EmbeddedModelField('Bid'), editable=False)
这篇关于django-nonrel从管理员中排除listfield的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!