tags:

views:

125

answers:

1

I have a model that contains a foreign key value, then in the form generated from this model, I want to auto select the record's key according to the record I'm adding the form's contents to...I've tried the below code, but it tells me QuerySet doesn't contain vehicle

stock = Issues.objects.filter(vehicle=id) 
form = IssuesForm(initial={'id_vehicle': stock.vehicle})

I'm a bit new to django btw so any ideas are highly appreciated

+2  A: 

filter always gives a QuerySet, which is a set of values. If you just want a single object, you should use get.

However I don't really understand why you need to do the lookup at all. You have the id value already, since you are using it to look up stock. So why don't you just pass id as the value for id_vehicle?

Daniel Roseman
I'll try your suggestion...thanks.