mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-12-01 14:04:02 +03:00
update form to have access to the request object
This commit is contained in:
parent
98ec89a575
commit
0d213f1439
|
@ -572,7 +572,6 @@ class UpdateModelMixin(object):
|
||||||
else:
|
else:
|
||||||
# Otherwise assume the kwargs uniquely identify the model
|
# Otherwise assume the kwargs uniquely identify the model
|
||||||
self.model_instance = model.objects.get(**kwargs)
|
self.model_instance = model.objects.get(**kwargs)
|
||||||
|
|
||||||
for (key, val) in self.CONTENT.items():
|
for (key, val) in self.CONTENT.items():
|
||||||
setattr(self.model_instance, key, val)
|
setattr(self.model_instance, key, val)
|
||||||
except model.DoesNotExist:
|
except model.DoesNotExist:
|
||||||
|
|
|
@ -212,9 +212,14 @@ class FormResource(Resource):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if data is not None or files is not None:
|
if data is not None or files is not None:
|
||||||
return form(data, files)
|
form_ = form(data, files)
|
||||||
|
else:
|
||||||
|
form_ = form()
|
||||||
|
|
||||||
return form()
|
if hasattr(self.view, 'request'):
|
||||||
|
form_.request = self.view.request
|
||||||
|
|
||||||
|
return form_
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -333,11 +338,17 @@ class ModelResource(FormResource):
|
||||||
if data is not None or files is not None:
|
if data is not None or files is not None:
|
||||||
if issubclass(form, forms.ModelForm) and hasattr(self.view, 'model_instance'):
|
if issubclass(form, forms.ModelForm) and hasattr(self.view, 'model_instance'):
|
||||||
# Bound to an existing model instance
|
# Bound to an existing model instance
|
||||||
return form(data, files, instance=self.view.model_instance)
|
form_ = form(data, files, instance=self.view.model_instance)
|
||||||
else:
|
else:
|
||||||
return form(data, files)
|
form_ = form(data, files)
|
||||||
|
|
||||||
return form()
|
else:
|
||||||
|
form_ = form()
|
||||||
|
|
||||||
|
if hasattr(self.view, 'request'):
|
||||||
|
form_.request = self.view.request
|
||||||
|
|
||||||
|
return form_
|
||||||
|
|
||||||
|
|
||||||
def url(self, instance):
|
def url(self, instance):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user