Z
Z
zelsky2015-08-02 16:35:55
JavaScript
zelsky, 2015-08-02 16:35:55

Timer on django form?

The user is authorized, and in front of him is a form, filled out and sent. How can I disable the form for 24 hours after that? You can't forget to send the o5 form for 24 hours, in general, for one user, where to google?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Barabanov, 2015-08-02
@zelsky

store the date of the last submission of the form by the user and do not display it (well, or submit) if 24 hours have not passed yet.

S
sim3x, 2015-08-02
@sim3x

https://docs.djangoproject.com/en/1.8/ref/models/f...

class Foo(models.Model):
    user = models.ForeignKey(MyUser)
    action_datetime = models.DateTimeField(auto_now_add=True)


from datetime import datetime, timedelta


def form_view(request):
    if Foo.objects.get(
        user=request.user, 
        action_datetime__gt=datetime.now() - timedelta(days=1)):
           # do what u want

In general terms, so

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question