tomchristie/django-rest-framework — Issue #149: FormResource.get_bound_form() should accept kwargs.
Author: btimby
Created: 2012-02-01 18:08:45+00:00
State: open

FormResource should pass along arbitrary kwargs to the form class. This would be helpful when using a ModelForm with the PUT method. You want to be able to pass an existing model instance to be updated...

```python
def put(self, request, name):
obj = ModelClass.objects.get(name=name)
form = self.get_bound_form(self.CONTENT, instance=obj)
return form.save()
```

So, the updated get_bound_form() method would be:

```python
def get_bound_form(self, data=None, files=None, method=None, form_kwargs=None):
"""
Given some content return a Django form bound to that content.
If form validation is turned off (:attr:`form` class attribute is :const:`None`) then returns :const:`None`.
"""
form = self.get_form_class(method)

if not form:
return None

if form_kwargs is None:
form_kwargs = {}

if data is not None or files is not None:
return form(data, files, **form_kwargs)

return form(**form_kwargs)
```