Questions tagged [drf-queryset]

127 questions
5
votes
2 answers

DRF: How to hide the password in serializers that use the depth option?

I'm using the below serializer for the User model, but when I use depth for handling foreign keys, the password shows in the User object. User serializer: class UserSerializer(serializers.ModelSerializer): class Meta: model = User …
5
votes
1 answer

annotate: whether a given value exists in m2m field

I have a query that retrieve an object like this: { "id": 1, "tags": [1, 2, 3] } I want to check whether a given tag (say, 1) exists in the tags field of the object, and annotate the result of the check as a field of the object: { "id":…
5
votes
1 answer

queryset vs filter_backends in django rest framework

I am new to DRF. I went through the example of filtering queryset at http://www.django-rest-framework.org/api-guide/filtering/#filtering-and-object-lookups This link contains description about queryset filtering, as well as DjangoFilterBackend. As…
Mangu Singh Rajpurohit
  • 10,806
  • 4
  • 68
  • 97
4
votes
2 answers

filter django queryset by onetoone model field property

i have two model classes and they are related by OneToOneField like here class Book(models.Model): is_user_ok = models.BooleanFiled() class Mybook(models.Model): book = models.OneToOneField( Book, related_name="Book", null=True,…
3
votes
3 answers

How to get top n rows in django rest framework serializers using serializers relations

I have a serializer that is working fine for all of the data, which is getting from the Database. I want to get top n numbers of rows sorted by some value. Below is my code in views.py: @api_view(['GET']) def org_api(request, org_id): if…
3
votes
1 answer

Django - How to set default ordering on ManyToMany field queryset

I have following models: class Hashtag(models.Model): ... created = models.DateTimeField(auto_now_add=True) ... class Tweet(models.Model): ... hashtags = models.ManyToManyField( to='Hashtag', …
msln
  • 1,318
  • 2
  • 19
  • 38
3
votes
0 answers

How to serialize nested generic relations in django rest frame work

there is a little bit complex model in the project. There are three models bind to each other by generic relations. Here is the example models: class Person(models.Model): first_name = models.CharField() last_name = models.CharField() …
Sencer H.
  • 1,201
  • 1
  • 13
  • 35
3
votes
0 answers

How can I reduce recursive MPTT tree queries when serializing with DRF

Working on an e-commerce project. Project has related models. Category model has MPTT inheritance. It using Django Rest Framework for communicate between API's. A foreign service recently wants me to put full Category path into XML response on my…
Sencer H.
  • 1,201
  • 1
  • 13
  • 35
3
votes
1 answer

Show and serialize the results of select_related() model method

I have two simple models: User (standard Django User) AND class Post (models.Model): class Post (models.Model): name = models.CharField(max_length=100) user = models.ForeignKey(User, on_delete=models.CASCADE) def __str__(self): return…
3
votes
1 answer

How can i use limit offset pagination for viewsets

Views.py class CountryViewSet(viewsets.ViewSet): serializer_class = CountrySerializer pagination_class = LimitOffsetPagination def list(self,request): try: country_data = Country.objects.all() …
Susaj S N
  • 960
  • 1
  • 10
  • 22
2
votes
1 answer

join 3 tables queryset Python Django

I need join 3 tables in a query on Django. I have two query's in MySQL, both return the same result, it doesn't matter to use one or the other query: Query with where SELECT dv.Division, COUNT(or.`ct_id`) AS `orders`, COUNT(CASE WHEN…
Manuel
  • 23
  • 1
  • 6
2
votes
1 answer

Passing Django query objects values() into Django Rest Framework Serializer

I'm trying to get the same output as my django query but the actual output differs when Django Rest Framework serves it. Added the following to my serializer but it kept leaving out the cart_assessments__risk_type out of the output. How do I make my…
2
votes
1 answer

Unit Test Using Forcing Authentication Django Rest Framework

I'm building RESTful API services using django rest framework, I've reached the point where i have to create an automated test for my RESTful API services. The sessionList api require token authentication, in case the user doesn't have the token he…
2
votes
1 answer

DRF ViewSet Returns QuerySet With Empty Values

I have a DRF ViewSet called "QueryCriteriaViewSet" which I'm using in a query builder which allows users to select a field and then select from related criteria. So, for example, a user can select the "reg_status" field and then select from the…
2
votes
2 answers

PageNumberPagination and a queryset without fixed order

According to the documentation, nothing special is required to enable pagination when using a class inheriting from GenericAPIView. I've looked in the code of django and django rest framework and the ViewSet queryset doesn't seem ordered. The…
1
2 3
8 9