我正在将django 2.0.8与Python 3.5和django-threadedcomments结合使用以进行评论。
我正在尝试实现一个支持某些“社交”功能的博客(是的,我知道django博客应用程序已经存在!)
如前所述,我正在使用django-threadedcomments进行评论。
以下是我的一些型号:
from django.db import models
from django.contrib.contenttypes.fields import GenericRelation
from threadedcomments.models import ThreadedComment
from django.conf import settings
class AbuseReport(models.Model):
owner = models.ForeignKey(settings.AUTH_USER_MODEL, blank=False, null=False, default=1, on_delete = models.CASCADE)
class Reportable(models.Model):
abuses = GenericRelation(AbuseReport)
class Meta:
abstract = True
class Like(models.Model):
owner = models.ForeignKey(settings.AUTH_USER_MODEL, blank=False, null=False, default=1, on_delete = models.CASCADE)
class Likeable(models.Model):
likes = GenericRelation(Like)
class Meta:
abstract = True
class ThumbVote(models.Model):
VOTE_TYPES = (
('U', 'Upvote'),
('D', 'Downvote'),
)
owner = models.ForeignKey(settings.AUTH_USER_MODEL, blank=False, null=False, default=1, on_delete = models.CASCADE)
vote = models.CharField(max_length=1, choices=VOTE_TYPES)
class Thumbvoteable(models.Model):
thumbvotes = GenericRelation(ThumbVote)
class Meta:
abstract = True
class ThumbvoteableReportableComment(Thumbvoteable, ThreadedComment):
pass
from foo.models import ThumbvoteableReportableComment \
Likeable, Reportable
# Create your models here.
class Post(Likeable, Reportable):
pass
class PostComments(ThumbvoteableReportableComment):
post = models.ForeignKey(Post, related_name='comments', on_delete = models.CASCADE)
from django.contrib import admin
from .models import Post, PostComments
class PostCommentsInline(admin.TabularInline):
model = PostComments
readonly_fields = ('thumbvotes',)
fields = ('comment', 'abuse_report_count')
class PostAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("title",)}
list_display = ('title', 'pub_date')
inlines = [PostFileInline, PostPictureGalleryInline, PostCommentsInline]
def save_model(self, request, obj, form, change):
obj.author = request.user
obj.save()
# Register your models here.
admin.site.register(Post, PostAdmin)
当我进入django管理页面时,出现以下问题:
abuses
字段likes
字段abuse_report_count
字段,也没有thumbvote
字段(均从父类继承)如何更改模型等以使字段显示在管理器中?