Questions tagged [django-rest-viewsets]

362 questions
1
vote
2 answers

Django-viewsets. How to get the ID parameter from the path in perform_create fun

I'm trying to do a REST in Django using the VIEWSETS library. I created a Container model that works well. Container is associated with the ContainerModerator model. The endpoint should be: POST containers/{container_id}/moderators One of the…
1
vote
1 answer

Can't submit a post request using Django rest framework ("detail": "CSRF Failed: CSRF token missing or incorrect.")

I am into a weird situation I am login into site and try to submit form if I use permission_classes = [AllowAny] or isAuthenticate classes I get error CSRF Failed: CSRF token missing or incorrect And in following scenario it gives a popup to…
1
vote
1 answer

Is there a way to use inheritance in django viewsets or do I have to rewrite the functions?

I am writting an API in Django Rest Framework. I am using viewsets however regular methods create() and update() do not do it for me and I have to rewrite them. Suppose that I need to do just one check to test if creation of an instance is legit,…
1
vote
2 answers

Django DRF - using basic search filter to do an multiple OR search

Im trying to do a multiple OR search with the basic Django filter. Ive tried the below URLs already but they only return the first result api/circuit/?search=AB5814765;AB827451;AB0923784 using a comma returns no results also. is there any syntax…
AlexW
  • 2,843
  • 12
  • 74
  • 156
1
vote
0 answers

Throttling Viewset using ratelimit doesn't work

I have a Django rest backend that takes data from frontend made in angular, and I've tried throttling the number of requests from the same Ip address to 5 per 10 minutes using ratelimit but was unable to do it. Since I'm new to this part of drf, I…
1
vote
1 answer

router.register(), AttributeError: module 'rest_framework.views' has no attribute

I don't know what I am doing wrong. I have been battling with this error for hours. I have opened all the suggestions I saw and implemented what they suggested but still, the error is pending router.register(r'^hmos/$',…
techstack
  • 1,367
  • 4
  • 30
  • 61
1
vote
2 answers

CreateModelMixin TypeError: __init__() takes 1 positional argument but 2 were given

I'm trying to insert a new row into a 2 column table where one column references the authenticated user (model references user model via a FK) and the other being a variable passed through the url. urls.py url('^(?P-?\d+.?\d+)/$',…
Joshua
  • 197
  • 12
1
vote
2 answers

Django Rest API merging delete/get/update/get methond in two class

At first you see my 4 method class in view.py: class ContactList(ListAPIView): queryset = Contact.objects.all() serializer_class = ContactSerializers # This is delete method class ContactDelete(DestroyAPIView): queryset =…
user11149657
1
vote
2 answers

Wrong redirects when using defaultRouter() for ModelViewSet in Django-REST-framework

I have a Django Project where i made 3 Different Apps: "blog", "users", "api". It is a Website where messages can be posted by using a model Post. I want to use an Django Rest API for accessing the Model. It works, but it messes with some redirects…
1
vote
1 answer

How to implement Redis Cache with Django Rest Framework?

I need to implement Redis cache with my Django Rest Framework site. But when I do load test using cache_page decorator with a class it improves the request per second but an error occurs "'function' object has no attribute…
1
vote
2 answers

DRF Viewset - Do not create but return if object already exists

Is it possible to override the create of a Viewset to first check if an object exists and, if so, return that object rather than creating it? Specifically, in my viewset, I have overriden the create function as follows: try: item =…
NickP
  • 1,354
  • 1
  • 21
  • 51
1
vote
1 answer

DRF : Generic way to inject additional info into request.data

I'm in a situation where I have a endpoint samples which represents a model sample via a ModelViewSet. My goal is, that when a user POST's against this endpoint with data like { "a":1, "b":2 , "c":3 } i want to be able to override/add…
Chgad
  • 820
  • 2
  • 7
  • 18
1
vote
2 answers

Django Rest Framework ViewSet filtering issue based on foreignkey User field

I have a django project that I am working on. There are two models in this project. There is a user and account model. I am integreating the django rest framework viewsets. I will include them below. I am now integrating the Django Rest Framework in…
Omar Jandali
  • 814
  • 3
  • 20
  • 52
1
vote
1 answer

Django Rest Framework modelviewset - updating fields before create

I have a modelviewset: class ExpenseViewSet(ModelViewSet): permission_classes = [permissions.IsAuthenticated, HasMetis] serializer_class = ExpenseSerializer def get_queryset(self): return…
Alex
  • 2,270
  • 3
  • 33
  • 65
1
vote
2 answers

Comparing instance of different models - Django REST Framework

I'am just looking for answer for my (seems to be stupid) question. I've already watched few stackoverflow posts but any of them was helpful :( My question is how to compare two instance of different models with different? Here is my case: I've got…