[Answer]-Django: Getting category from add in view

1👍

In the first line of the view, you’re returning a queryset, not an object. While this queryset will contain only one objec, others constructed using a filter will have multiple members.

To return an object as opposed to a queryset with that line, use either of the following lines:

theadd = adds.objects.get(id=pk)
theadd = adds.objects.filter(id=pk)[0]

You should only ever use the first on unique indexed properties (i.e. id), as it will fail with an error if there is more than one object that matches the criterion.

👤TimD

Leave a comment