S
S
Sergey Nizhny Novgorod2016-01-14 04:14:28
Django
Sergey Nizhny Novgorod, 2016-01-14 04:14:28

How to update user state in Django?

Hello guys.
Now I am working on a project where there will be paid content, which will be available to the user only after payment.
Task: The user enters the system, makes a payment, gets access to restricted content.
I think that it is necessary to bind some additional parameter to the model, which will act as a free/paid-User classifier. And already with the help of this parameter in the view, display one or another template.
Am I right, or is there some simpler and more understandable solution for this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman Kitaev, 2016-01-14
@deliro

If there are only two user states:
1) The user does not have access to paid content
2) The user has access to paid content
Then this is the norm. I would add a datetime nullable paid_till field (paid until [if there is some subscription, of course]) and create a method

def is_paid(self):
    if self.paid_till is None:
        return False
    return self.paid_till >= timezone.now()

And they would check whether the user has a subscription or not.

Z
zelsky, 2016-01-14
@zelsky

deliro.ru/posts/kak-rasshirit-model-user

V
Vladimir, 2016-01-14
@vintello

what if you look at it from the other side?
you need to distinguish between user-accessible content, not user state.
that is, you just need a content manager depending on the status of the user. one of the many user statuses is paid content.
so the problem looks different already?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question