Home > OS >  Save progress or actions of user in django?
Save progress or actions of user in django?

Time:10-08

I have a serious of task which needs to be completed by users when they signup ! How to keep track on this ? For now am checking if data exsist in more than 5 tables (like address, education etc). I think this is not a good way of doing this ! As when ever user logins, i need to check if they have finished all the basic tasks and then allow them to do other things..

On doing research, i have few options:

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

I think the second option is more effective, as it just fetches on row from the table instead of fetching multiple rows !

Or please suggest any new option to track this !

CodePudding user response:

add json field in model and dump user's actions in it. plus use "from django_extensions.db.fields.json import JSONField" instead of "models.JSONField" because it doesn't go well with SQL

CodePudding user response:

  1. Action - the model name should be singular
  2. I would use a BooleanField in User model, so you don't have to do other selects, if he has already finished all the steps and you can do just:
if not request.user.finished_all_steps:
  # select from Action and let him finish it
  pass

and then it's up to you, if you wanna use Action.actions as a JSONField, or you make a row per every action

  • Related