1👍
First of all, If you want to use class based views, you should read some more about them. They are thoroughly explained on Django’s docs and you can read about the specific generics of the framework you’re using on the REST framework docs too. I’m not saying that you haven’t read those, just that you seem to be missing some basic concepts that are explained there.
Now, to the problem at hand, if you look at the doc’s of the generic view you’re extending, you can see that it represents the endpoints for a single instance, meaning that it won’t act on all your model’s instances (as you seem to assume).
Also, you can see that this view is built on top of a series of other classes, the more critical one being GenericAPIView
. On there you can see two things:
- The
queryset
class field in this context is meant for filtering the posible instances you can manipulate, not obtaining the specific instance described on your url. - The
lookup_field
is the field that defines which attribute from your model will be used for getting the actual instance. You should define this field to whatever field you’re going to use on your url to identify your object (generally it’s pk). It’s also important to note that the url should include a keyword argument corresponding to this value.
Internally, the view will take care of calling the get_object
method, which usese the lookup_field
value to find the specific model, and then feed that object to the serializer and return the result back to the client.
DISCLAIMER: I’ve never used Django REST framework, I put this answer togheter by reading the relevants docs and based on my experience.
0👍
I guess you need this:
Resolve function (django 1.4)
Then in your view class method you can do:
temp1, args, kwargs = resolve(self.request.path)
- [Answer]-Using server response as foreign key table entry?
- [Answer]-Django Hide Processing Page
- [Answer]-Loading a test file using AJAX