Questions tagged [django-rest-viewsets]

362 questions
0
votes
1 answer

Django REST permission classes don't work together inside an OR but work as expected independently

I'm having troubles putting two permissions together using an OR operator. The documentation says: Doc Provided they inherit from rest_framework.permissions.BasePermission, permissions can be composed using standard Python bitwise operators. For…
nck
  • 1,673
  • 16
  • 40
0
votes
1 answer

How to get data that belongs to specific user in Django Rest Framework?

I haved Format_List model with relation with Django user and now I want to get the data belongs to specific user by giving user id or after user login. models.py class Format_List(models.Model): class Meta: db_table =…
0
votes
1 answer

Django Rest Framework - Register Multiple Viewsets Against a Single URL, Based on Header Data

I need to use Multiple ViewSets with the same URL where the active ViewSet needs to be selected dynamically based on request header logic. Django rest framework allows you to do this to register the viewsets against different…
0
votes
1 answer

how can make new object in django-restful-framework by post method?

i have this model class Product(models.Model): name = models.CharField(max_length=50) price = models.PositiveIntegerField() i want make a new object using post method in restframework in django but i dont know what should i do please help…
user12782685
0
votes
1 answer

Django Rest, How to update a single field of the object in viewset? I get IntegrityError for the required fields

Now I have a big catalog object and with one request I want to modify a single field of it.( The rest will remain the same). I have required fields so I get this error when I do PATCH request. null value in column "team_id" of relation…
0
votes
1 answer

Django DRF - "hide user" (a mandatory field) in api webview

I have a simple model: class Store(models.Model): name = models.CharField("address", max_length = 128, null = True, blank = True) open = models.PositiveIntegerField("status", default = 1, choices = [(0,0), (1,1)]) user =…
xtlc
  • 1,070
  • 1
  • 15
  • 41
0
votes
1 answer

How can I skip authentication in a Django APIRequestFactory call?

So essentially I want to make a request to a ViewSet without requiring to authenticate, does Django APIRequestFactory make this possible? This works: from django.test import TestCase from .views.SomeViewSet from rest_framework.test import…
0
votes
1 answer

AttributeError: 'function' object has no attribute 'get_extra_actions' in function view

views.py @api_view(['GET', 'POST']) def poll(request): if request.method == "GET": question = Question.objects.all() serializer = QuestionSerializer(question, many=True) return JsonResponse(serializer.data, safe=False) …
0
votes
1 answer

Django: ModelViewSet update() returns TypeError: update() got an unexpected keyword argument 'pk' during image upload

I want to upload an image from the user's profile page. The URL from where I am uploading the image is the Detail page. That's why it has the user ID at the end of the URL. But, when I make a PATCH request after adding the image in Postman, Django…
0
votes
0 answers

Django Rest Framework Include ManyToMany attributes in slash with all features

I'm using Django Rest Framework, here's my code: models.py class Course(models.Model): name = models.CharField(max_length=200) class Formation(models.Model): name = models.CharField(max_length=200) courses =…
0
votes
0 answers

DRF ViewSet: Change appearance of field

I have a model like this: ## model: class Product(models.Model): id = models.PositiveIntegerField(unique = True) price = models.ForeignKey(Price, on_delete = models.CASCADE, null = True, blank = True) ## serializer: class…
xtlc
  • 1,070
  • 1
  • 15
  • 41
0
votes
0 answers

Disaply Django Fieldset values according to previously selected option?

I'm using Django's built-in Admin functionality to support a web app's admin users. So far I'm also using mixins and "rest_framework - viewsets" library to have automated a generic CRUD API. In my admin.py files, I've used fieldsets to easily create…
0
votes
1 answer

Django Rest Framework: Second parameter in url being constructed with a dot (.) instead of /

I've got the following method in my View: @action(detail=True, methods=['delete']) def remove(self, request, *args,**kwargs): print("here") I've created a test for this endpoint. But haven't been able to get the correct url. When I do url =…
0
votes
1 answer

How would one go about implementing a search by image function in DjangoRestFramework?

I am building an app which lets the user to upload an image to the server and the server will return the most similar image in the database. I implemented a basic algorithm to do this, but I can not figure out how to actually let the user upload the…
0
votes
1 answer

Django Rest Framework URL for custom action not working

I've got the following custom action in my view: class OrderAPIViewSet(viewsets.ViewSet): def create(self, request): print("Here: working") @action(detail=True, methods=['post']) def add(self, request, *arg, **kwargs): …