I have defined a custom action for a ViewSet And the viewset is registered to url in the conventional way The URL /api/users/gender/ works. But I don’t know how to get it using reverse in unit test. (I can surely hard code this URL, but it’ll be nice to get it from code) According to the django documentation, the following
Tag: django-rest-framework
How to pass choice display name to model serialize in Django REST framework?
My env is Django 2.0.3, DRF 3.8.2 and Python 3.6.4. I have a model in serializers.py: Where destination field is choice field of 3 elements: This is my models.py: ..And I return JSON like this: How to return destination field with his display name? For example: Would be great to have something like get_FOO_display() in serializers.py, but it’s not working.
django-rest-framwork got AttributeError when attempting to get a value for field
I want to get all prodcut table values with join product_ratings table. I did somthing like this but this code give me AttributeError. So I did product_ratings = ProductRatingSerializer(many=True) in product serializer and used this value in the field, but it’s not working: The full error message: view : its serializer classes: related model class : Answer Default reverse lookup
Getting an Assertion error in my django application(1.8.4)
I am getting an exception value on running application : (“Creating a ModelSerializer without either the ‘fields’ attribute or the ‘exclude’ attribute has been deprecated since 3.3.0, and is now disallowed. Add an explicit fields = ‘__all__’ to the StockSerializer serializer.”,) Answer As the error message says, the required attribute is fields with an ‘s’, not field.
How to access request body when using Django Rest Framework and avoid getting RawPostDataException
I need to get the raw content of POST request body (as a string) yet when I try to access request.body I’m getting an exception: I am aware that it is adviced to use request.data instead of request.body when using Django Rest Framework, yet for the purpose of validating digital signature I have to have the request body in a
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 authenticate itself via JWT. If I do the same with an API client (in my case, Postman), everything works. This is
Django Rest Framework – AssertionError Fix your URL conf, or set the `.lookup_field` attribute on the view correctly
I’m trying to return a single object specific to a user (not a queryset), without 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
How can I serialize a queryset from an unrelated model as a nested serializer?
I’m trying to add a nested serializer to an existing serializer based on some criteria of the parent model, not a foreign key. The use case is to return a ‘Research’ object with an array of ‘ResearchTemplate’ objects that are identified by filtering on a Postgres ArrayField. Models class Research(TimeStampedModel): category = models.CharField(max_length=100, choices=RESEARCH_TEMPLATE_CATEGORIES, default=’quote’) body = models.CharField(max_length=1000, blank=True, default=”)
What is the proper way of testing throttling in DRF?
What is the proper way of testing throttling in DRF? I coulnd’t find out any answer to this question on the net. I want to have separate tests for each endpoint since each one has custom requests limits (ScopedRateThrottle). The important thing is that it can’t affect other tests – they have to somehow run without throttling and limiting. Answer
how to parse json array in django
I am new in django rest api framework and using get i am fetching the a json array whose api is this https://api.coursera.org/api/courses.v1?q=search&query=machine+learning and i am not able to parse it.Actually i want to store all the names and send them to .html file .I have used this code but didnot worked for me. Answer This actually has nothing to