mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 08:14:16 +03:00
error_data
-> errors
Prefill form for instance view.
This commit is contained in:
parent
024780a974
commit
55f7dd9bce
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user