Questions tagged [drf-queryset]

127 questions
0
votes
1 answer

Is there a best practice to create a Django query with extensible filters?

Suppose I have a "find invoice page" where users can input (or not) different fields in order to search for invoices to display them in a list. Suppose this list of fields might grow over time with additional db fields. My current (working) solution…
0
votes
2 answers

Using the serializer context in a Serializer field queryset definition

I'm looking for a way to use the serializer context defined in the ModelViewSet using the get_serializer_context to be used in the queryset declaration of a specific SlugRelatedField: class ReservationViewSet(ViewPermissionsMixin,…
0
votes
2 answers

Django Rest Framework: append value to ListAPIView

StackOverflow community, I've got the following serializer and view: serializers.py class PricetrendSerializer(serializers.ModelSerializer): timestamp = serializers.DateTimeField() average_price = serializers.IntegerField() class Meta: model =…
0
votes
1 answer

Django Rest Framework: changing output format of annotated field in queryset

Hello StackOverflow community, I am currently struggling with specifying an output format in my views.py. I have a column "date" which is using following format: 2021-01-14. In my response, I would like to change the date format so that it only…
DevDjas
  • 59
  • 2
  • 7
0
votes
1 answer

Django Rest API: View definition delete queryset

I'm still pretty new to creating views in Django Rest Framework, I can make basic views but I still have no clue about definitions so please help me out here. I've got this View which gets the answers of a question (by a given question id). The list…
SJ19
  • 1,933
  • 6
  • 35
  • 68
0
votes
1 answer

Trying to override a get_queryset in a view

class OwnerList(generics.ListAPIView): serializer_class = OwnerDetailSerializer # queryset = Person.objects.filter(customuser__userrole__role__name='OWNER').distinct() permission_classes = [IsAuthenticated] filter_backends…
0
votes
1 answer

Django won’t let me query a table by any attribute bar ‘pk’

So I’m trying to query my ‘Profile’ table by the relation attribute ‘owner’, which links to another table ‘User’. However, when I attempt to query by this attribute, I get the following error: 'AssertionError: Expected view UserProfile to be called…
0
votes
1 answer

Pass additional attribute to django-filter

I'm using django-filter together with DRF. I have a favourite-model, which is linked to several other models through a GenericRelation. To filter for entries which have a favourite-flag, I've created a custom FavouriteFilter, which I add to the…
Christian Benke
  • 517
  • 7
  • 26
0
votes
1 answer

serializing image data from diffrent fields

From my little knowledge on how serializers work, I know we mostly use modelserializers, and for that, we would have a model for all we want to serialize but how can I join all the images in the different models and then serialize them. These are my…
0
votes
1 answer

given a date start and date end, give me the duration in an array of 24 values corresponding to hours of the day

I am very new to Django rest framework and stack overflow even, I was struggling with finding a title so please feel free to give a better alternative. I have a set of jobs that get posted to a database. the jobs are now grouped per machine and per…
0
votes
1 answer

Django - values_list CSV

I'm trying to export CSV in Django and using values_list to select field i want to export. My First Try class ExportCSV(APIView): def get(self, request, *args, **kwargs): incidents = Incident.objects.filter( …
z3r0
  • 139
  • 16
0
votes
1 answer

Filter datetime field python

Json receiving python: { "str_ini": "2020-06-05", "fnsh_date": "2020-06-20", } I use str_ini and fnsh_date as a parameter to build my query. OrderModel.py: fservice = models.DateTimeField(db_column='FService') # (In DB this field is…
Manuel
  • 23
  • 1
  • 6
0
votes
0 answers

Object of type Publisher is not JSON serializable in Django Multiple Pagination

I have tried DjangoRestMultipleModels Pagination from here, Now I'm facing JSON serializable error! Views.py from drf_multiple_model.views import ObjectMultipleModelAPIView from drf_multiple_model.pagination import…
0
votes
1 answer

How i can get list of data by SELECT * LIKE condition in DRF?

How can I make a request for DRF, as if it would be like a request for SELECT by LIKE condition? Now they are displayed to me like this but I want to output depending on the values in the columns user_id and user_members_id. I have this…
0
votes
1 answer

How to filter useing look up method "in or range" and make sure if any of the item in the list is not available then returns empty queryset

My code snippet: boards_qs = BoardRate.objects.filter( Q(room_status="OP") & Q(hotel_log__date__range=[check_in_date, check_out_date]) & Q(hotel_log__hotel__pk__in=hotel_id_list) & …
Navid
  • 53
  • 10
1 2 3
8 9