You probably have to validate it yourself. You probably should do
this at the form level. I don't think there's a smart way to do
that in Django.
1. Pass user into the form's __init__.
2. Check the number of user's feedback in the form's clean()
method and raise ValidationError if user has left enough feedback.
class FeedbackForm(forms.Form): def __init__(self, user, *args, **kwargs): self.user = user def clean(self): super().clean() if Feedback.objects.filter(user_id=self.user.pk).count() >= 3: raise ValidationError(['You have already left feedback 3 times.']) ======================
form = FeedbackForm(request.user, request.POST)
I have a feedback app in which the user signs in, logs in and gives feedback. i wish to limit the number of feedbacks a user can give. how to do this and where? shall I user validation?
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMO5YArF_cYq_-E2Zw0COTVFW20x5H6k4eo700i0ULD19BX9cQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.