1👍
I can’t see how there can be any validation errors if the data just came straight out of the DB. However, it’s quite easy to do this – instead of passing the data in as initial,
pass it as data
, just as if it came from a POST.
formset = ArticleFormSet(data=my_data)
This sets the form as bound, and triggers validation.
1👍
Use
formset = ArticleFormSet(data=my_data)
Very important, my_data should be a dict with this format
data = {
'form-TOTAL_FORMS': u'2',
'form-INITIAL_FORMS': u'2',
'form-MAX_NUM_FORMS': u'',
'form-0-title': u'Test',
'form-0-pub_date': u'1904-06-16',
'form-1-title': u'Test',
}
form-TOTAL_FORMS and form-INITIAL_FORMS are mandatory!!!
- [Answered ]-How do I properly nest serializers in Django REST Framework?
- [Answered ]-Manual CSRF Verification
- [Answered ]-ImportError: No module named celery with django in virtual env
Source:stackexchange.com