我想使用 django mptt 创建类别和子类别系统。我的尝试:
from django.db import models
import mptt
class Category(models.Model):
name = models.CharField(max_length=255)
category = models.ForeignKey('self', null=True, blank=True, related_name='children')
mptt.register(Category, order_insertion_by=['name'])
class Post(models.Model):
title = models.CharField(max_length=255)
text = models.TextField()
category = models.ManyToManyField(Category)
我的管理员.py
from django.contrib import admin
from xxxx.xxx.models import *
from mptt.admin import MPTTModelAdmin
admin.site.register(Category, MPTTModelAdmin)
admin.site.register(Post)
我的错误:
类别没有名为“父”的字段