I might be worth checking out some sort of API library, like 
https://github.com/orokusaki/django-jsonrpc-2-0, which will allow you to 
perform whatever business logic you need to, and then simply return 
something like {"success": True, "errors": errors_list} - your templates 
and ordinary views could be leaner, if you A) separate your AJAX 
functionality from your non-AJAX views, and B) create a central client-side 
template (e.g., https://github.com/janl/mustache.js/) for rendering the 
contents of your model.

On Friday, February 8, 2013 7:38:18 PM UTC-5, Kelly Nicholes wrote:
>
> What's the best practice for this?  In my function based views, I'd check 
> if the form is_ajax() and if so, validate the form, render_to_string it to 
> a form template, and return that in a json dump along with a status code. 
>  Then I check the status code to see if there are errors.  If so, I close 
> the modal that the form is in, notify the user of successful addition, and 
> move on.  If there are errors, I replace the form's HTML in the modal with 
> the new HTML that contains the form with error messages.  This sucks 
> because I have to do this for every form and for every view that I have.  

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to