Questions tagged [drf-queryset]

127 questions
1
vote
1 answer

Extract children with a given condition - Django MPTT and Django rest framework

In this tree I want to do a query so that only the first generation of the red circle is extracted. But the condition is that the value of each circle must be greater than zero, ie the green circles: Serializers: class…
mrbf
  • 512
  • 1
  • 7
  • 23
1
vote
1 answer

How to sort list in DRF?

I've got two models with onetoone relation user and blog. While listing users I want to have users with blog on top. How to order users so that users with blog is on first of list and secondary order by users id? My Models: class User(BaseModel): …
1
vote
0 answers

how to retrieve data using uuid in drf

halo guys i wan to retrieve a particular object using DRF RETRIEVEAPIVIEW using UUID as my pk but i'm getting { "detail": "Not found." } error below is my APIVIEW and url class RetrieveProfile(generics.RetrieveAPIView): lookup_field = 'id' …
Tosin Ayoola
  • 77
  • 1
  • 9
1
vote
1 answer

field_name = ordering[0].lstrip('-') throws IndexError: tuple index out of range in DRF rest_framework\pagination.py

I am getting error IndexError: tuple index out of range while using CursorPagination of DRF. my code- class CursorSetPagination(CursorPagination): page_size = 10 page_size_query_param = 'page_size' ordering = '-created_at' class…
1
vote
1 answer

How to serialize the foreign key field in django rest framework

I work on a project with DRF where I'm getting serializer data as follows which is absolutely fine: { "message": "Updated Successfully", "status": 200, "errors": {}, "data": { "id": 8, "user": 2, "item": 1, …
1
vote
1 answer

Try, Except is not giving required result in django serializers create method. the getobject statements gives required result if put is outside try:

class BeneficiarySerializer(serializers.Serializer): class Meta: model = Beneficiary fields ='__all__' def create(self, validated_data): try: available =…
1
vote
1 answer

Annotate in django object using function

I have two models Parent, Child class Parent(models.Model): id = models.IntegerField(...) class Child(models.Model) id = models.IntegerField(...) parent = models.ForeignKey(Parent, ...) wanted = models.CharField(default="yes") I…
1
vote
2 answers

Django Rest Framework: How to Dynamically return subset of fields

I would like to filter by fields name and get back a subset instead of having back all my fields name. For example here I am filtering by id and name. It should return me only this two dimension in json format. I have found many solution on the…
1
vote
1 answer

Does Django Rest Framework execute query for SerializerMethodField

I have following Django Rest Framework Serializer: from rest_framework.serializers import SerializerMethodField from posts.api.serializers import CommentSerializer class PostSerializer(ModelSerializer): comments = SerializerMethodField() …
msln
  • 1,318
  • 2
  • 19
  • 38
1
vote
2 answers

Django Rest FrameWork Reduce number of queries using group by

I am writing an api using Django Rest Frameworks. The api fetches a list of clients.A Clients has many projects. My api should returns the list of clients with number of projects completed, pending and total. My api works, but it has too many sql…
tessie
  • 964
  • 3
  • 14
  • 24
1
vote
1 answer

Django annotated queryset with latest values for some fields

I have a model which store some marketing performances: class DailyPerformance(models.Model): class Meta: unique_together = ('route_hash_value', 'datetime_tz') ordering = ('-datetime_tz',) route_hash_value =…
1
vote
2 answers

How to get each column as one list from a Django QuerySet over DRF

Using Django-REST-framework, I have the following view: class MyRESTfulAPIView(APIView): permission_classes = [IsAuthenticated, MyCustomPermision] def get(self, request): data = MyModel.objects.values('field1').annotate(field2=...,…
1
vote
1 answer

How to write the functionality in generics.ListAPIView which can be written in APIView in Django DRF

I have a function base view which get 2 parameters from URL http://127.0.0.1:8000/api/v1/contest/0b36d92a-51a7-4752-9df1-e5f2733116c1/paintings/ @api_view(['GET',]) @permission_classes([AllowAny]) def Contest_detail_by_id_and_category(request, id,…
manish singh
  • 87
  • 1
  • 13
1
vote
1 answer

filter_queryset with boolean field

I have the following view: class MessagesViewSet(ModelViewSet): """ A simple ViewSet for viewing and editing the messages associated with the user. """ authentication_classes = [TokenAuthentication, ] permission_classes =…
user12177026
1
vote
0 answers

"detail": "Not found." DRF

I get "detail": "Not found." when I visit this link localhost:8000/portal/finalyears/1/members/2 but when I use the following link it shows the details: localhost:8000/portal/finalyears/1/members/1 My urls.py file contains: …
1 2
3
8 9