I have a newform that accepts credit card input. Users can have
multiple credit cards stored in the system. In the process of the user
adding credit cards I want to check that there are no duplicates. I am
doing the following...

            if not
CreditCard.objects.filter(number=form.cleaned_data['number'],
user=request.user):
                card = form.save(commit=False)
                card.user = request.user
                card.save()
                return HttpResponseRedirect('/success/page/')
            else:
                # manually set form error
                form._errors['__all__'] = "<ul class=\"errorlist
\"><li>Duplicate Credit Card</li></ul>"

This seems kind of hacky, but it really seems like it makes sense to
show this as a form error. The only other way I could think to solve
this was to pass the request to the model and then check the above in
the clean method, however this seems just as bad as it breaks the
separation between the view and the model. Does anyone have a
different suggestion as to how to do this cleanly?

Best,
Jamie


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to