Django Rest Framework JWT Unit Test

I am using DRF with the JWT package for authentication. Now, I’m trying to write a unit test that authenticates itself with a JWT token. No matter how I try it, I can’t get the test API client to …

Django Rest Framework – AssertionError Fix your URL conf, or set the `.lookup_field` attribute on the view correctly

I’m trying to return as single object (not a queryset) that is specific to a user without them having to specify an identifier/pk within the requested URL. Each user has an organisation FK. i.e. http://website/organisation and not http://website/organisation/1 I’m receiving the following error, since it’s expecting this identifier: AssertionError: Expected view OrganisationDetail to be called with a URL keyword argument named “user__organisation_id”. Fix your URL conf, or set the.lookup_fieldattribute on the view correctly. How/What do I need to specify when using the RetrieveModelMixin/GenericAPIViewso that it returns a singular object linked by a FK? My view class: Related url: url(r’^api/v1/organisation/$’, OrganisationDetail.as_view()),

Django rest framework override page_size in ViewSet

I am having problem with django rest framework pagination. I have set pagination in settings like – ‘DEFAULT_PAGINATION_CLASS’:’rest_framework.pagination.PageNumberPagination’, ‘PAGE_SIZE’: 1 Below …

Field name `username` is not valid for model

I am attempting to use rest-auth supplied serialisers to GET (*with headers) user details from the defined endpoint /rest-auth/user/ (*with headers (Content-Type: application/json Authorization: …

Django Rest Framework Database Error Exception Handling

Is there any way to have Django Rest Framework automatically respond with HTTP_400_STATUS’s when there are database exceptions? (IntegrityError and so on) Example: I have a model with a unique …

Overriding Django-Rest-Framework serializer is_valid method

I have a quick question about overriding is_valid. Self is a rest_framework.serializers.ModelSerializer. I’m trying to figure out if there is a better way to modify internal data than reading/…

All fields in ModelSerializer django rest framework

models.py: class Car(): producer = models.ForeignKey(Producer, blank=True, null=True,) color = models.CharField() car_model = models.CharField() doors = models.CharField() …

How to run tests django rest framework tests?

I’m learning django rest framework. I wrote a simple test like this: from rest_framework import status from rest_framework.test import APITestCase class ClinicTestCase(APITestCase): def getList(…

Get current user in Model Serializer

Is it possible to get the current user in a model serializer? I’d like to do so without having to branch away from generics, as it’s an otherwise simple task that must be done. My model: My serializer: And my view: How can I get the model returned, with an additional field user such that my response looks like this: Answer I found the answer looking through the DRF source code. The key is the fact that methods defined inside a ModelSerializer have access to their own context, which always includes the request (which contains a user when one is

Django REST Framework – Separate permissions per methods

I am writing an API using Django REST Framework and I am wondering if can specify permissions per method when using class based views. Reading the documentation I see that is quite easy to do if you …