Questions tagged [django-rest-viewsets]

362 questions
0
votes
1 answer

How to add a custom action for the same route as standard one in a ViewSet

Suppose, we have a ViewSet class: class SomeViewSet(viewsets.ViewSet): def create(self, request): pass def custom_action(self, request): pass and we register SomeViewSet as follows: some_router =…
Dmytro
  • 190
  • 8
0
votes
1 answer

Return Empty Page if There's No Filtering Provided in DRF and Django Filters

I have a ViewSet as below: class EntryViewSet(viewsets.ModelViewSet): queryset = Entry.objects.all() serializer_class = EntrySerializer filter_backends = [DjangoFilterBackend, OrderingFilter] filterset_class = EntryFilterSet …
0
votes
1 answer

ModelViewSet does not provide `create` url in Django Rest Framework

I have a viewset as below: class EntryViewSet(viewsets.ModelViewSet): queryset = Entry.objects.all() serializer_class = EntrySerializer permission_classes = [permissions.IsOwnerStaffOrReadOnly] filter_backends = [DjangoFilterBackend,…
Eray Erdin
  • 2,633
  • 1
  • 32
  • 66
0
votes
1 answer

Django Rest framework: Relate 2 tables

I'm new at python and Django. I have a problem relate 2 tables Participants Model lass Participant(models.Model): id = UUIDField(primary_key=True, default=uuid.uuid4, editable=False) first_name = CharField(max_length=255) last_name =…
0
votes
1 answer

Django REST Framework : How to define nested viewsets and get more explicit lookup_field names?

Context I have two viewsets, with their own routers to automatically generate the URLs from them : ModelAViewset ModelBViewset For now, only the ModelAViewset details can be access through the following URL : {root_url}/model-a/ With…
0
votes
0 answers

django get method with argument not working

I am trying to make a get request with an ID argument in django as the doc says in https://docs.djangoproject.com/en/3.2/topics/class-based-views/ but I can't seem to make it work. The request is arriving in the backend as expected. "GET…
0
votes
1 answer

Django Rest Framework (DRF) sets JSON field to Empty in the to_internal_value function

So I am trying to upload file AND Post JSON data to my API following this solution. I have created the Parser, placed it in my viewset. I even receive the image and the JSON data in the to_internal_value function, which i think runs AFTER the parser…
0
votes
0 answers

when i wanna update my object, fields with DateField or ImageField are blank, they dont have any data but they are saved in database

models.py class Log(models.Model): product = models.ForeignKey(ProductInfo,on_delete=models.PROTECT,default=0,verbose_name='کالا') number = models.IntegerField(null=False,blank=False,default=0,verbose_name='تعداد') date_to_recived =…
user15446178
0
votes
1 answer

DRF ViewSet - dealing with query params

I want to change a queryset in my ViewSet depending on query parameters. I see that there is a list of tags in query params, but when I try extract them I get just last tag as a string. And I have no idea why and how it should work. Can someone…
0
votes
1 answer

Django Viewset retrieve not working with Default Router

I am trying to access a specific comment using the retrieve method in Django View sets. I am using a default router in order to route my urls. I am able to list all comments at api/posts/, but am unable to get a single comment at api/posts/1. I am…
Phil Cho
  • 131
  • 3
  • 14
0
votes
2 answers

Display data that no model exists in a serializer - Python - Django - Django Rest Framework

I have a "Model-Viewset-Serializer" and I need my Serializer to display additional fields that don't exist in the model. Model: class MyModel(models.Model): id = models.UUIDField(primary_key=True, unique=True, default=uuid.uuid4, editable=False,…
0
votes
1 answer

How to overwrite create method in Viewset to accept my custom serializer in DRF?

I need to create a instance of my model, but in my request.data i don't have the correct information for my serializer. class CotizacionViewSet(viewsets.ModelViewSet): serializer_class = CotizacionSerializer permission_classes =…
0
votes
1 answer

File upload in Django rest

I have created an api for uploading 'profilepicture' for an existing user. Models.py class ProfilePicture(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile_picture') profile_pic_path =…
0
votes
1 answer

Pass a value to an api and return a specific object

I have created an api where #urls.py router = DefaultRouter() router.register('login', GetUserViewSet, basename='get_user') urlpatterns = [ path('', include(router.urls)), ] #views.py class GetUserViewSet(viewsets.ReadOnlyModelViewSet): …
0
votes
1 answer

How to preprocess uploaded images in views wih Django Rest Framework, and Django

I decided to process the image being uploaded to get the GPS location in views. the code work and saves to the db but I get prompted to with a FileNotFoundError at /api/v1/addWaste/ [Errno 2] No such file or directory: '/tmp/tmpnsym9i2b.upload.jpg'…