django - 空的 Django 内联说字段是必需的
问题描述
在 django admin 中,我正在尝试创建一个新条目,但内联表单中的字段会抛出错误,说即使我不想创建新的内联,它们也是必需的。
楷模:
class Attribute(models.Model):
name = models.CharField(choices=ATTRIBUTE_CHOICES, max_length=max_choice_len(ATTRIBUTE_CHOICES))
amount = models.PositiveIntegerField()
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey()
def __str__(self):
return f'{self.name} {str(self.amount)}'
class Item(models.Model):
...
attributes = GenericRelation(Attribute)
行政:
class AttributeInline(GenericTabularInline):
model = Attribute
extra = 0
class ItemAdmin(admin.ModelAdmin):
inlines = [AttributeInline]
class Meta:
model = Item
admin.site.register(Item, ItemAdmin)
解决方案
推荐阅读
- magento2 - 重复运行模式...我们找不到您想要的用户的角色
- c# - HashSet 项可以更改为 Set 中的相同项
- java - Deserializing arbitrary JSON in Java with Gson and respecting integers
- python-2.7 - ImportError: cannot import name Document
- python-2.7 - how to duplicate output to terminal in bs4 in text file
- regex - Removing parentheses and everything in them with Regex
- arrays - Ionic 3 将数据插入 Firebase RTDB
- python - IDLE 如何打印 sys.stdout.encoding 不支持的字符(python 3.7)
- php - How to store data into json.file with variable name from database using php
- r - 在 R 中粘贴 5 个列组的复杂问题