Questions tagged [drf-queryset]

127 questions
0
votes
1 answer

How to select all using "__in" in drf on empty list?

For example, if i had to select specific ids I can do this using: id_list=[1,4,7] Blog.objects.filter(pk__in=id_list) But the problem is id_list is being populated using filters selected in front end. so initially id_list will be…
0
votes
2 answers

Getting reverse relationship model values django

I have the following models: class RestaurantItemImages(models.Model): restauraunt_item = models.ForeignKey('RestaurantItem',on_delete=models.CASCADE) image = models.ImageField() updated = models.DateTimeField(auto_now=True,…
0
votes
1 answer

Django Admin Inline an object

I have Two models Question and QuestionChoice. QuestionChoice has a ForeignKeyfield which points to Question. I would like to have these as inline stack views in the admin view but I'm getting an error. Models: class Question(models.Model): …
0
votes
1 answer

change the queryset from a view in a filter

I would like to have default behaviour where queryset in a view returns records where publish_at date is less than some date. I also want to have boolean DRF filter that if set to true returns all the records no matter what publish_at date…
0
votes
1 answer

Django Rest Framework: nested serializer for duplicate rows, in the case of foreign key

serializer.py class Car(serializers.ModelSerializer): geography=Geography(read_only=True) class Meta: model = Car fields = ['car_id', 'geography'] models.py class Car(models.Model): car_id =…
0
votes
0 answers

Why validate_ triggered 3 times? Django Rest Framework

I have following cutsom base Serializer: class CustombBaseSerializer(Serializer): def get_object(self, model, **kwargs): try: return model.objects.get(**kwargs) except model.DoesNotExist: raise…
msln
  • 1,318
  • 2
  • 19
  • 38
0
votes
1 answer

Cant get queryset to return list of objects that is descending by tag matches

I am running django 2.1.7, DRF and using taggit. I am writing my own custom queryset to find tags that an object has. The url: example.com/api/tags=books,headphones,sleep Should return JSON that has objects in order from contains most tags to…
Edwin Carra
  • 97
  • 1
  • 7
0
votes
0 answers

I can't get an object name by requested user with drf serializer and CreateAPIView

I have: object1 with OneToOneField with user, object2 with ForeignKeys to user and object1. in the serializer, I want to retrieve the name of object1 and make it as a default name in object2. createAPIView prohibit get operation while I can use…
omeraiman
  • 841
  • 6
  • 13
0
votes
3 answers

Type error to create and update my list in django rest framework

I'm trying to use my api to create and update products in a bundle. I did so: model.py class Business(models.Model): name = models.CharField(max_length=155) class Product(models.Model): business = models.ForeignKey( Business, …
Joey Fran
  • 598
  • 2
  • 24
0
votes
0 answers

DRF - CreateAPIView Nested Serializer

I've an interesting question and want expert views on it. I've the following models. class A(models.Model): b = ForeignKey(B) c = ForeignKey(B) d = ForeignKey(B) class B(models.Model): pass class C(models.Model): pass class…
Praful Bagai
  • 16,684
  • 50
  • 136
  • 267
0
votes
1 answer

Django Rest Framework - perform Put request by passing a JSON object instead of just ID

I'm working on a Project using Python(3), Django(1.11) and DRF(3.6) in which I have to perform a PUT request by passing a nested nested instead of an ID. Here's What I have tried: models.py: class Actor(models.Model): id =…
Abdul Rehman
  • 5,326
  • 9
  • 77
  • 150
0
votes
2 answers

Django Rest Framework filter on the base of JSONField nested objects

I'm working on a Project using Python(3), Django(1.11) and DRF in which I have to filter the data on the base of a json object field which is saved as JSONFIELD in db model. Here's what I have tried: # model.py from django.db import models import…
0
votes
1 answer

How to ensure that users can only access/update data created by them

I wish to create an API that allows a user to access/update details of Books only uploaded by them. The user should not have permission to access/update a book that has been created by someone else. This is my models.py: from…
Vinay
  • 699
  • 4
  • 22
0
votes
2 answers

Django Rest Framework validation in POST method of APIView

I'm new to DRF and trying to build a rest api, I need to make an api for task executions not just for CRUD, that's why I have override the POST method of APIView as: class DeploymentsList(viewsets.ModelViewSet): queryset =…
Abdul Rehman
  • 5,326
  • 9
  • 77
  • 150
0
votes
1 answer

Get a queryset from another Model in a queryset in Django

class V(models.Model): title = models.CharField(max_length=100, blank=True, default='') doc = models.ForeignKey(D, on_delete=models.CASCADE, default='') upload_time = models.DateTimeField(auto_now_add=True) class Meta: …
mrhaoji
  • 336
  • 5
  • 19
1 2 3
8
9