views:

38

answers:

1

I'm trying to set up piston on my Django project. I ran into a brick wall when I tried to POST (create) a new entry on a model that contains a ForeignKey: location.

Here is the exact error I receive: Cannot assign "u'1'": "Fest.location" must be a "Location" instance.

In the above example, I tried to send over location=1 in the POST.

What am I doing wrong here? Surely Foreign Keys are supported on CREATEs...

===UPDATE===
To be clear, I'm using PISTON to handle these REST API requests. My Handler currently looks like this:
class FestHandler(BaseHandler):
model = Fest

+1  A: 

You need to assign an actual object. Something like the following should work:

loc = Location.objects.get(pk=1)
obj.location = loc
obj.save()

where obj is the model you're trying to save which has location as a foreign key.

ars
I don't think this will work in a PISTON handler, but I could be misunderstanding something...
Sunsu
This actually ended up working, I am just new to Django and didn't know exactly how to implement it.
Sunsu