微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Django表格内联显示当前用户为默认值

如何解决Django表格内联显示当前用户为默认值

我有两个模型,媒体和评论 审核任何媒体项目,然后审核存储在审核模型中。

在管理站点中,我创建了表格内联,以便我可以查看媒体及其评论

enter image description here

当我点击添加另一条评论时,会添加一条新的评论行。 我需要的是认情况下它应该将审阅者显示为当前登录用户

这是评论模型,

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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?