I'm trying to save a new object from a django model using a POST data querydict. This is part of a PISTON handler. I've seen this done in numerous examples, but I just can't get it to work.
Here is my code:
class FestHandler(BaseHandler):
model = Deal
def create(self, request):
"""
Creates a new fest.
"""
attrs = self.flatten_dict(request.POST)
postcopy = request.POST.copy()
if self.exists(**attrs):
return rc.DUPLICATE_ENTRY
else:
loc = Location.objects.get(pk=attrs['location'])
postcopy['location'] = loc
fest = Fest(postcopy)
fest.save()
return fest
Here is the error I receive every time:
Exception was: int() argument must be a string or a number, not 'QueryDict'
I realize what the error means, so basically I am asking how I can save a new "Fest" by passing in the whole POST dictionary without having to type in the keys manually every time like this:
loc = Location.objects.get(pk=attrs['location'])
fest = Fest(
location=loc,
name=attrs['name'],
description=attrs['description'],
details=attrs['details'],
)
Thanks for your help!