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
filteralways gives a QuerySet, which is a set of values. If you just want a single object, you should useget.However I don’t really understand why you need to do the lookup at all. You have the
idvalue already, since you are using it to look upstock. So why don’t you just passidas the value forid_vehicle?