在django中保存用户的进度或操作



我有一项艰巨的任务,需要用户在注册时完成!如何跟踪?目前,我正在检查数据是否存在于5个以上的表中(如地址、教育等)。我认为这不是一个好方法!当用户登录时,我需要检查他们是否完成了所有的基本任务,然后允许他们做其他事情。。

在做研究时,我有几个选择:

Option1: Create a new model and store all progress on each row 
and then fetch all the rows to check if required is completed.
Option2: Create a new model and store the finished actions in a array, for instace:
Class Actions:
owner = models.ForeignKey(User, on_delete=models.CASCADE)
actions = ArrayField(models.CharField(max_length=128))
And with these, i can append all the finished task one by one, like {emailverification,
personal_details,education_details} etc
And then use the above to work on the conditions

我认为第二个选项更有效,因为它只从表中获取一行,而不是获取多行!

或者,请建议任何新的选项来跟踪这一点!

在模型中添加json字段,并在其中转储用户的操作。加上使用";从django_extensions.db.fields.json导入JSONField";而不是";模型。JSONField";因为它不适合SQL

  1. Action-模型名称应为单数
  2. 我会在用户模型中使用BooleanField,这样你就不必做其他选择,如果他已经完成了所有步骤,你只需要做:
if not request.user.finished_all_steps:
# select from Action and let him finish it
pass

然后,如果你想使用Action.actions作为JSONField,或者你为每个动作制作一行,那就取决于你了

最新更新