当mptt.django中的父级别低于5时,如何隐藏字段"内容"?我希望在后代为5时编辑一个字段。
class Menu(MPTTModel):
name = models.CharField(max_length=50, blank=True, null=True)
content = models.TextField(verbose_name='content')
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
def __str__(self):
return self.name
forms.py
class BookAdmin(admin.ModelAdmin):
def get_form(self, request, obj=None, **kwargs):
if parent and parent.level <= 5:
self.exclude = ("content", )
我想创造一些想法