I'm writing a Django app that performs various functions, including inserting, or updating new records into the database via the URL.
So some internal application sends off a request to /import/?a=1&b=2&c=3
, for example.
In the view, I want to create a new object, foo = Foo()
and have the members of foo
set to the data in the request.GET dictionary.
Here is what I'm doing now:
- Request sent to
/import/?a=1&b=2&c=3
- View creates new object:
foo = Foo()
- Object is updated with data.
Here is what I got thus far:
foo.a = request['a']
foo.b = request['b']
foo.c = request['c']
Obviously this is tedious and error prone. The data in the URL has the exact same name as the object's members so it is a simple 1-to-1 mapping.
Ideally, I would like to do able to do something like this:
foo = Foo()
foo.update(request.GET)
or something to that effect.
Thanks!