Questions tagged [django-rest-viewsets]

362 questions
0
votes
1 answer

How to restrict users from creating a model that they don't have access to

I have Workspace and Request models. A Workspace can have multiple Users assigned to it. Any User can create a request. I want to restrict a user from creating a request on only those Workspaces that he/she has access to. Currently, in my create…
0
votes
2 answers

Multi parameter method in django viewset router

May i know how to setup method with multiparameter like=> @action(methods=['get'], detail=True) def byshiftid(self, request,shiftid): print("Hello World") query = self.get_queryset().get(shiftid=shiftid) …
lwin
  • 3,784
  • 6
  • 25
  • 46
0
votes
1 answer

Is there a way I can get comments for only one specific article using Django rest framework?

Now I have tried to use nested routers to solve the issue but still Iwant to be able to create new comments without sending the blog post ID from the request body. I want to be able to get it from request parameters. So, how can I get this id one…
0
votes
2 answers

What is the difference between method handlers such .get, .post and actions such as .list, .create

I am learning Django Rest Framework and one of the things I have noticed is that Viewsets provide actions such as .list, .post instead of method handlers such as .get, .post which in turn are provided by Views. The documentation says that actions…
Saurabh_Jhingan
  • 190
  • 5
  • 20
0
votes
1 answer

Django2 is trying to render Jinja2 templates, even though it's a REST API

We're utilizing the django-rest-framework to create a RESTful API and using generic views or view sets to create the endpoint views. There is no templating happening, all the frontend is in React. However, upon watching the traces in Datadog, we're…
0
votes
1 answer

My rest api view always creates a new object instead of put , delete and patch

I am creating a restapi view which should be a one and all endpoint for all the crud.But no matter what i do it always executes post method .The terminal shows me that for e.g the patch method has been executed but it always does post and therefore…
0
votes
1 answer

Post Request shows 403 not found error even tough permission class in django rest framework view sets is set to allow any

I am trying to store the data in the form using post method. To do that i have set the permissions as AllowAny. I have checked the POST method using Postman and it works but when I use axios to post the same data it returns 403 error. I have already…
0
votes
1 answer

Is there a way to aggregate a field in Django Rest Framework that will have the summation of one field

Currently I've figured it out on how to aggregate a single column in my serializers.py but the sum of my salary field will go to the total_salary field in my serializer and total_salary isn't in my models. Now my problem is that how can I do…
xed
  • 79
  • 9
0
votes
1 answer

DRF: viewsets lookup_field ImproperlyConfigured

I'm migrating my DRF from generics to viewsets, but I receive this error: Could not resolve URL for hyperlinked relationship using view name "monument-detail". You may have failed to include the related model in your API, or incorrectly configured…
0
votes
1 answer

How to get the relative path of files in the django ListAPIView?

Want a relative path of the image to be returned from the API: Want "/media/image.jpg" format, not "http://0.0.0.1:8000/media.image.jpg" to be returned for the API For the following, getting full URL i.e. "http://0.0.0.1:8000/media.image.jpg"…
0
votes
1 answer

How to post request for multiple strings in django rest framework?

I am writing a viewsets that takes in an array of string values from the user and validates a table based on the post request. I dont know how to take in an array in request.POST from the user and use the rest APIs in the Postman. As for…
Phoenix
  • 373
  • 1
  • 4
  • 20
0
votes
1 answer

How to add user in perform_create viewset (django rest framework)?

I want to make a "comment" table. On the table, there will be a field containing user_id that created the comment. The user related with the comment table is from Django default user model. This is the Comment model: class Comment(models.Model): …
0
votes
1 answer

Best method to create an object with many to many field using Django RF API

I have started a project with an idea that's more than I know I can handle but hey... some of us learn the dumb way right? Currently have 2 models: User model that uses the AbstractUser class and then I have a Role model that provides many roles…
0
votes
2 answers

Register your Django router

When I use route.register without base_name like;route.register(r'codes', SmsCodeViewset) An error occurred; AssertionError: basename argument not specified, and could not automatically determine the name from the viewset, as it does not have a…
0
votes
1 answer

RestFul API endpoints with Django Rest Framework Class based views

I have the following 4 class based views in DRF to perform CRUD operation on a model called Trips. from rest_framework import generics class TripCreateView(CreateAPIView): #code that creates a Trip class TripListView(ListAPIView): #code…