如何解决Django表格内联显示当前用户为默认值
我有两个模型,媒体和评论 审核任何媒体项目,然后审核存储在审核模型中。
在管理站点中,我创建了表格内联,以便我可以查看媒体及其评论,
当我点击添加另一条评论时,会添加一条新的评论行。 我需要的是默认情况下它应该将审阅者显示为当前登录用户。
这是评论模型,
class Review(models.Model):
"""Represents a review made by an Account on an object
"""
content_type = models.ForeignKey(ContentType,on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
review_item = GenericForeignKey('content_type','object_id')
reviewer = models.ForeignKey(
Account,blank=True,null=True,on_delete=models.SET_NULL,help_text="Account of the reviewer",)
RECOMMENDATION_CHOICES = [
("pending","pending"),("accepted","accepted"),("declined","declined"),]
recommendation = models.CharField(
max_length=64,choices=RECOMMENDATION_CHOICES,default="pending",help_text="Recommendation of the reviewed object",)
description = models.TextField(
blank=True,help_text="Optional field for reviewer to make comments",)
这里是admin.py代码,
class ReviewInline(GenericTabularInline):
"""Inline for Review models
"""
model = Review
# Limit extra inline forms
extra = 1
class MediaAdmin(admin.ModelAdmin):
"""Admin interface for the Media model
"""
# *** Form settings ***
# Split up the forms into fieldsets
fieldsets = [
("Settings",{
"fields": [
"status","severity","nsfw",],}),("Data",{
"fields": [
"source","type","url","file","image","title","description","category",("Meta",{
"fields": [
"data","created_at","updated_at","published_at",]
# Specify m2m relations with a widget
filter_horizontal = ["category"]
# Set inlines
inlines = [ReviewInline,PersonInline]
# Specify read-only fields
readonly_fields = ["created_at","data"]
# When using inline we need to exclude these fields
exclude = ["persons"]
# *** List settings ***
# Set which columns in list overview
list_display = [
"title","source","url_link","get_persons","get_categories","status",]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。