error_data -> errors

Prefill form for instance view.
This commit is contained in:
Marko Tibold 2012-09-08 21:56:18 +02:00
parent 024780a974
commit 55f7dd9bce
2 changed files with 9 additions and 4 deletions

View File

@ -22,7 +22,7 @@ class CreateModelMixin(object):
self.object = serializer.object
self.object.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.error_data, status=status.HTTP_400_BAD_REQUEST)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
class ListModelMixin(object):

View File

@ -248,11 +248,16 @@ class DocumentingTemplateRenderer(BaseRenderer):
# Creating an on the fly form see: http://stackoverflow.com/questions/3915024/dynamically-creating-classes-python
fields = {}
for k, v in self.view.get_serializer().fields.items():
object, data = None, None
if hasattr(self.view, 'object'):
object = self.view.object
serializer = self.view.get_serializer(instance=object)
for k, v in serializer.fields.items():
fields[k] = field_mapping[v.__class__.__name__]()
OnTheFlyForm = type("OnTheFlyForm", (forms.Form,), fields)
form_instance = OnTheFlyForm(self.view.get_serializer().data)
if object:
data = serializer.data
form_instance = OnTheFlyForm(data)
return form_instance
def _get_generic_content_form(self, view):