Allow users to submit django form once per day

106 views
Skip to first unread message

Nkansah Rexford

unread,
Jul 23, 2015, 11:08:12 AM7/23/15
to Django users
I want to allow users to submit a django form once, and only once everyday. After submitting the form, the form wouldn't even show (server-side checkings, I don't want to use JS or client side thing; easily 'tamper-able')

What is the best way to do so in Django?

Robin Lery

unread,
Jul 23, 2015, 11:19:38 AM7/23/15
to django...@googlegroups.com

You can save the datetime of the last form submission and check whether its oneday or not in the view. If its one day then show pass the form or else dont.

Hope this helps.

On 23 Jul 2015 20:38, "Nkansah Rexford" <seanm...@gmail.com> wrote:
I want to allow users to submit a django form once, and only once everyday. After submitting the form, the form wouldn't even show (server-side checkings, I don't want to use JS or client side thing; easily 'tamper-able')

What is the best way to do so in Django?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b310e40f-8baa-449a-bcef-36052d0256a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maxim Boyarskiy

unread,
Jul 23, 2015, 11:28:58 AM7/23/15
to Django users, seanm...@gmail.com
You can check how django rest framework solves it:
http://www.django-rest-framework.org/api-guide/throttling/

Nkansah Rexford

unread,
Jul 23, 2015, 3:32:58 PM7/23/15
to Django users, robi...@gmail.com

You can save the datetime of the last form submission and check whether its oneday or not in the view. If its one day then show pass the form or else dont.

Hope this helps.


I do know I have to save the date stamp, but the question is Where? On the model class, the user class, or in a text file?

Carl Meyer

unread,
Jul 23, 2015, 3:37:36 PM7/23/15
to django...@googlegroups.com
The database. Either a new field on a user or profile model, or on the
model the form is for, or a new model specifically for this purpose.
Hard to say with the info you've given so far which of those makes most
sense for your case, any of them could work. (E.g. "on the model the
form is for" only makes sense if that model is "owned" by a single user,
not edited by multiple users.)

Saving persistent data on a Python class (if that's what you meant by
"the model class" or "the user class") doesn't work; you'll lose the
data if the server restarts.

Text file would work, but that's a lot of hassle to no good end when you
have the database available, whose entire purpose is to store persistent
data for you.

Carl

signature.asc

Nkansah Rexford

unread,
Jul 29, 2015, 9:33:01 PM7/29/15
to Django users, seanm...@gmail.com
Okay guys,

After some days of thinking about the problem, I'm through with this approach, which is totally horrible, I guess, but works.

The code snippet can be found here: https://gist.github.com/seanmavley/c9a4af36c2693d9b437a

I'm posting back here because although the approach works, its not 'sustainable' nor reusable easily. Plus, if someone could guide me (this time, code-wise) to do a better job with it, I'll really appreciate. FBV or CBV, i'm all ears.

I'm currently using the approach in the link above on http://logecg.khophi.co

thanks
Reply all
Reply to author
Forward
0 new messages