Questions tagged [django-rest-viewsets]

362 questions
1
vote
1 answer

drf ModelViewset does not validate Unique Constraint failed when unique_together is used

I am using djangorestframework==3.12.1 Here is how my code looks like:- models.py class Product(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) name = models.CharField(max_length=100) price =…
1
vote
2 answers

How to solve Method "POST" not allowed 405

I'm using Django Rest Framework for API and I faced this problem. In views.py my class inherits from ModelViewSet, but for some reason it doesn't allow making a POST request. For frontend I'm using React JS and I make a POST request from there. And…
1
vote
0 answers

DRF: get_object in action from custom queryset

I have ViewSet like this class CustomViewSet( RouteActionArgumentsMixin, viewsets.ModelViewSet ): serializer_class = MySerializer def get_queryset(self): MyModel.objects.filter(...) I want to add an action in this…
alis01
  • 169
  • 1
  • 3
  • 11
1
vote
1 answer

Django Rest Framework Routing: Reverse for 'orders' not found. 'orders' is not a valid view function or pattern name

I'm not quite sure I'm understanding how routing works in DRF. I went through the documentation but still haven't grasp the differences. I've got the following view: from django.shortcuts import render from django.shortcuts import…
1
vote
0 answers

Django Rest Framework: How to properly test a ViewSet?

I'm new to testing in DRF. I have the following ViewSet where I'm only allowing the 'List' and 'Retrieve' actions: class RecipeViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, …
1
vote
1 answer

Problem in showing foreign key relation in view

I have a Land model with three relation which one of them is Letter and the model is: class Letter(models.Model): land = models.ForeignKey('Land', on_delete=models.DO_NOTHING) image = models.ImageField(null=True,…
1
vote
2 answers

Django Rest Framework: foreign key field is required in viewset or serializer

I am very new to Django Rest Framework (DRF). I have read that viewsets are very good, because it reduces the amount of code, but I found it more complex. Description: Imagine that I want to implement a phonebook API, in which we have some users and…
1
vote
1 answer

How to dynamically update a viewset in Django Rest Framework

I think I am just putting this code in the wrong place but was wondering if someone could help out here. I wanted to get an item from the db for the last business day. This works fine, but it seems the below gets compiled when i start the app with…
bmccormick
  • 75
  • 1
  • 8
1
vote
1 answer

Why DRF Nested Serializer is returning an error

I am using django rest framework for my rest api based project. I am using nested serializer to save child model object along with parent object. Below is snap of my code This is my parent model : class DeliveryNote(models.Model): …
1
vote
1 answer

django rest framework using action decorator to add path to view financial statement in url

I need the following URLs to work where ticker would stand for a stock ticker such as AAPL or AMZN, and is stands for income_statement. localhost:8000/stocks/ localhost:8000/stocks// localhost:8000/stocks//is/ in the views.py file…
1
vote
0 answers

Excel File as Serializer Response in Django Rest Framwork

I am using ModelViewSet class to upload a of csv file, do some processing on it and save the output as an excel file in local directory. Now I want to send this excel file back as response for the same request. However I am not able to send back the…
1
vote
2 answers

Trying to do an INNER Join and display the result on the API

This question has been asked before but I cannot use any of the answers to my case. I'm trying to have the equivalent of this, to show the results on the API. SELECT denom_name,retail_name,retail_adr FROM denomination d INNER JOIN Retailer r ON…
Andy K
  • 4,944
  • 10
  • 53
  • 82
1
vote
1 answer

Django Admin Shows Instance Created But Cannot See It In DRF View

I am following a course on DRF. It basically is creating a Q&A site. Now I tried answering a Question using the DRF interface. But when I look at the question, it still shows answer count as zero. But the answwers are visible on the Django Admin…
1
vote
3 answers

Custom error message on Create User on DRF ModelViewSet

I'm writing a Django Rest API using Django Rest Framework and in it I have a base custom user User and two kinds of user that inherit from User, Doctor and Pacient. Each one has a different endpoint, so to create a Doctor we make a POST request to…
1
vote
2 answers

Create Object (in ViewSet class) with Celery Task in Django

Hello I encountered a problem which i am not able to solve by myself. I tried to call function create_with_celery inside create but it didnt work How should I call create.delay with proper arguments? I don't know how to properly call create…