I’m having some issues with double-posting on my site. I figure a simple unique constraint across all the relevant fields will solve the issue on a database level, but then it just produces a nasty error page for the user. Is there a way I can turn this into a pretty form error instead? Like a non_field_error? Or what approach should I take?
I’m having some issues with double-posting on my site. I figure a simple unique
Share
Maybe something like this will help you:
The
clean()method will allow you to access all fields of the form which might be useful if you have a combined unique key. Otherwise a (sightly shorter)clean_your_unique_key()might suit you better.And please note that under rare circumstances (race conditions) the form validation might not report a duplicate entry (but it’s of course reported by the database engine). But for most applications the provided example will be the easier and more maintainable one, so I still recommend this approach.