![]() ![]() To add the two fields onto the user model, you should extend the user model with a profile model like so: class Profile(models.Model): In addition, as pointed out in comments, the current_streak should be saved on the user/profile model. Then, to ensure that the streak would not stay at (for example) 2 until they submitted the next post, a check is run every time the user viewed their streak to see if last_answered was more than 24 hours away. Every time the user would upload a log, last_answered was set to the current time. ![]() The method I used was to add a last_answered field onto the user/profile model. I've created a journaling app with a similar streak system. Super(ModelAnswer, self).save(args, kwargs) Self.current_streak = answers_created_yesterday.current_streak + 1 If answers_created_yesterday is not None: ![]() # get the categories created yesterday to maintain the streakĪnswers_created_yesterday = ( Here is my main logic part this is not working as per required def save(self, *args, **kwargs): User = models.ForeignKey(User, on_delete=models.CASCADE)Ĭurrent_streak = models.PositiveIntegerField( I tried this code in django but any help in any language will be valuable class ModelAnswer(BaseModel): Streak is actually based on user and answer if user adds answer than streak is maintained. If the user adds a new data record once every 24 hours streak is one irrespective of how many records he/she adds and streak is 0 if he/she fails to add with in next time period and adds by +1 in next 24 hours timeframe from last record added. Here is how streak gets counted in snapchat I am failing to build logic regarding streak feature similar to Snapchat. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |