最小化标记系统数据库成本

时间:2019-08-24 22:38:52

标签: django postgresql django-models django-views postgresql-9.4

我正在尝试找出一种制作标记系统的方法,该系统不需要每次用户标记视频时都在数据库(Postgres)中输入新实例。 (代码下方/代码上方的额外上下文)我想输入的字段是“说明”,“时间戳”和“标记选择”。

所以我想知道这是否行得通。如果我创建一个Flag模型并使其自己的“正整数字段”(“戈尔”,“过度暴力”等)成为“旗帜选择”,并相应地增加字段,然后组合帖子的ID,标记帖子的原因说明以及通过用逗号将新条目分隔成一个TextField(在用户模型中而不是Flag模型中,这样我就知道是谁标记了任何帖子)来将时间戳记成一个字段...一个文本字段最终会变得太大吗?重要提示:每次查看并关闭标志时,都会从该字段中将其删除(在下面的上下文中)

上下文:在Flag模型中,将有一个post_id字段以及Excessive Violence Gore等。是正整数字段,每次有人提交标志时都会增加。然后,在用户模型中,将有一个字段,其中将包含类似以下内容的字段。 (逗号表示数据库中“ post_id”,“ description”和“ timestamp”字段的划分)

5, "Another flag from the same user in the same TextField.", 2019:9:15
# New Entry
...

然后要从该字段中获取标志,我将使用正则表达式与视图(将特定视频作为标志管理页面的参数传递)结合使用,以从TextField中获取post_id, description, timestamp (记录切片位置),然后在标记状态为“已关闭”后,该功能将删除该切片(以post_id开头,以时区结尾,以逗号分割)

这项工作有效吗?最终结果应该是...当标记某帖子时,同时创建一个新的Flag模型(如果这是来自用户的第一个标志/该帖子的第一个标志),则创建一个'flag_info'字段在用户模型中,将post_id,描述和时间戳输入到所述字段中。如果该用户标记了另一个视频,则会在标记模型中为该特定帖子创建一个新实例,并且标记选择(“戈尔”,“过度暴力”等)会增加。同时,将post_id,description和timestamp附加到与以下"post_id; description; timestamp,"相同的字段中,并获取特定标志,请使用正则表达式(并在审核页面上进行进一步处理)来解析post_id(用于查看特定帖子(将通过其他函数返回),说明和时间戳。

如果这很难理解,请原谅我,我仍在尝试自己解决这个问题。

我没有通过Google或任何其他搜索引擎找到关于此的任何信息。

标记模型

class Flag(models.Model):
    FLAG_CHOICES =(
        ('Sexually Explicit Content', 'Sexually Explicit Content'),


        ('Child Abuse', 'Child Abuse'),  # High priority, auto send to admin, ban if fake flag

        ('Promotes Definition Terrorism', 'Promotes Definition Terrorism'), # High priority, auto send to admin ban if fake flag

        ('Gore, Self Harm, Extreme Violence', 'Gore, Self Harm, Extreme Violence'),
        ('Spam/Misleading/Click-Bait', 'Spam/Misleading/Click-Bait'),
        ('Calling For Mass Flag', 'Calling For Mass Flag'),

        ('Doxing', 'Doxing'),

        ('Animal Abuse', 'Animal Abuse'),
        ('Threatening Behaviour', 'Threatening Behavior'),

        ('Calls To Action', 'Calls To Action')

    )
    STATUS_OPTIONS = (
        ('Open', 'Open'),
        ('Being Reviewed', 'Being Reviewed'),
        ('Pending', 'Pending'),
        ('Closed', 'Closed'),
    )
    objects = models.Manager()
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, null=True)
    object_id = models.PositiveIntegerField()
    content_object = GenericForeignKey('content_type', 'object_id')

    # Make positive integer fields for flag_choices so we can increment count instead of making a new instance every time
    sexually_explicit_content = models.PositiveIntegerField(null=True)
    child_abuse = models.PositiveIntegerField(null=True)
    promotes_terrorism = models.PositiveIntegerField(null=True)
    gore_harm_violence = models.PositiveIntegerField(null=True)
    spam_clickbait = models.PositiveIntegerField(null=True)
    mass_flag = models.PositiveIntegerField(null=True)
    doxing = models.PositiveIntegerField(null=True)
    animal_abuse = models.PositiveIntegerField(null=True)
    threating_behaviour = models.PositiveIntegerField(null=True)
    calls_to_action = models.PositiveIntegerField(null=True)
    sexualizing_children = models.PositiveIntegerField(null=True)
    # Increment the above fields when a flag with corresponding offence is submitted

    who_flagged = models.TextField(null=True) # This will allow me to get all users who flagged a specific post (split by commas, and use a function to loop through the newly formed list of user ids, then on each iteration. I would be able to grab the user model for futher operations

    flagged_date = models.DateTimeField(auto_now_add=True, null=True) 
    flag_choices = models.CharField(choices=FLAG_CHOICES, max_length=100, null=True) # Required Choices of offences
    status = models.CharField(choices=STATUS_OPTIONS, default='Open', max_length=50, null=True)

    def get_rendered_html(self):
        template_name = 'vids/templates/vids/moderation.html'
        return render_to_string(template_name, {'object': self.content_object})

用户模型或自定义用户配置文件模型

class CustomUser(models.Model):
    ...
     reported = models.TextField() # This will hold all the information about the users flag

# Meaning the following things will be in the same 'box' (
flag_info) in the DB... and will look like this...

 " post_id = 4; description = 'There was something in the background against the rules.'; timestamp = 2019:9:25,"

然后,当同一用户标记另一个视频时,将在“ flag_info”字段中附加以下内容...

所有这些都是一个很大的长字符串。

post_id = 24; description = "There was something in the background that showed my email."; timestamp = 2019:10:25,' 
# To get flag_info from a user, I would do the following in a view

def get_flag(user, post_id):
    # User is going to be the the user model that we need to pull from
    # post_id is so I can use regex to pull the slice
    # This is really simplified since it would take a while to write the whole thing
    info = user.flag_info
    split = info.split(",")
    for i in split:
        if i[0] == post_id:
            # do something with it

    # Alternatively I could do this
    for i in split:
        new = i.split(';')
        # position 0 is the post_id, position 1 is description and position 3 is timestamp...Here I would do further processsing

要跟踪谁标记了我将在Flag模型中标记TextField的内容,然后每次用户标记帖子时,他们的user_id都会记录在所述TextField中。当我们需要查看标志时,在用逗号分隔“ who_flagged”之后,我将使用“ get_flag”功能。它将提取我需要处理的字段。

由于我没有成千上万的视频/用户,所以我无法测试该字段最终是否会变得太大。

0 个答案:

没有答案