Questions tagged [django-rest-viewsets]
362 questions
                    
                    20
                    
            votes
                
                8 answers
            
        'CityListViewSet' should either include a `serializer_class` attribute, or override the `get_serializer_class()` method
I am assuming by the error in the title, once more here for clarity
'CityListViewSet' should either include a `serializer_class` attribute, 
or override the `get_serializer_class()` method.
that my serializer isn't connected to my view, which in my…
        user6781560
                    15
                    
            votes
                
                4 answers
            
        Difference between ViewSet and GenericViewSet in Django rest framework
I have a Django rest framework GenericViewset for which I am trying to set up pagination as follows:
#settings.py
REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 
         'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE':…
         
    
    
        Amistad
        
- 7,100
- 13
- 48
- 75
                    15
                    
            votes
                
                7 answers
            
        How to Not allow the PUT method at all but allow PATCH in a DRF ViewSet?
PUT and PATCH are both part of the same mixin (The UpdateModelMixin). 
So if I extend it like so:
class UserViewSet(mixins.UpdateModelMixin, GenericViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer
Both PUT and PATCH…
         
    
    
        SilentDev
        
- 20,997
- 28
- 111
- 214
                    10
                    
            votes
                
                2 answers
            
        What's the difference between a Viewsets `create()` and `update()` and a Serializers `create()` and `update()`?
Over here: http://www.django-rest-framework.org/api-guide/viewsets/#modelviewset it says "The actions provided by the ModelViewSet class are .list(), .retrieve(), .create(), .update(), .partial_update(), and .destroy()."
Over here:…
         
    
    
        SilentDev
        
- 20,997
- 28
- 111
- 214
                    9
                    
            votes
                
                3 answers
            
        Django rest api - searching a method field with the search filter
im trying to filter search a rest api page and want to use a method field as one of the search fields, however when I do this I get an error stating the field is not valid and it then lists the field in my model as the only valid…
         
    
    
        AlexW
        
- 2,843
- 12
- 74
- 156
                    9
                    
            votes
                
                1 answer
            
        Overriding Djangorest ViewSets Delete Behavior
I have defined a Model like this: 
class Doctor(models.Model):
    name = models.CharField(max_length=100)
    is_active = models.BooleanField(default=True)
My Serializer: 
class DoctorSerializer(serializers.ModelSerializer):
    class Meta:
      …
         
    
    
        QuestionEverything
        
- 4,809
- 7
- 42
- 61
                    8
                    
            votes
                
                3 answers
            
        CSRF Failed: Origin checking failed - http://localhost:8000/ does not match any trusted origins
Please help me solve the problem.
I was building an app consisting of Django Rest Framework and ReactJS. I used ViewSets.
my error:
response data:
{"detail":"CSRF Failed: Origin checking failed - http://localhost:8000/ does not match any trusted…
         
    
    
        nOybek
        
- 305
- 1
- 4
- 7
                    8
                    
            votes
                
                2 answers
            
        Django-filters does not work with the Viewset
I have been trying to use django-filters but the objects are not getting filtered. Also, the permission is not working for the partial_update views
I have a Viewset which has the basic actions like - list(), retrieve(), destroy(), partial_update()…
         
    
    
        5parkp1ug
        
- 462
- 6
- 17
                    8
                    
            votes
                
                1 answer
            
        How can i have two models in one serializer in django
I created API Views using django rest framework, I have a model which icsconsist of list of states in it and it associates with another model called country by the help of country(which consist of list countries) foreignkey I am trying to insert new…
         
    
    
        nithin singh Gm
        
- 129
- 1
- 2
- 10
                    7
                    
            votes
                
                2 answers
            
        Global Exception Handling in Django-rest-framework
Is there a way to handle all the exceptions globally without using try-except block in django rest framework.
I want to convert  html error page that django is throwing to a customised json object response.
I have created an exception.py file in my…
         
    
    
        Shubham Kumar
        
- 105
- 1
- 1
- 8
                    7
                    
            votes
                
                3 answers
            
        Django DRF add request.user to modelserializer
I am using django rest framework, and I have an object being created via a modelviewset, and a modelserializer. This view is only accessible by authenticated users, and the object should set its 'uploaded_by' field, to be that user.
I've read the…
         
    
    
        Alex
        
- 2,270
- 3
- 33
- 65
                    7
                    
            votes
                
                1 answer
            
        when to map http methods to view methods django rest framework
I have seen viewsets implemented like this:
can we expand on this line of code in the django rest frameworks docs:
"If we need to, we can bind this viewset into two separate views, like so:"
user_list = UserViewSet.as_view({'get':…
        user6781560
                    7
                    
            votes
                
                3 answers
            
        Filtering Django ModelViewSet List From Url Parameter
Hi I have a model like: 
class Appointment(models.Model):
    hospital = models.ForeignKey(Hospital, on_delete=models.CASCADE)
    patient = models.ForeignKey(Patient, on_delete=models.CASCADE)
My View looks like:
class…
         
    
    
        QuestionEverything
        
- 4,809
- 7
- 42
- 61
                    6
                    
            votes
                
                2 answers
            
        Django REST API accept list instead of dictionary in post request
I am trying to consume data from a callback API that sends the POST request in this format:
[
  {
    "key1": "asd",
    "key2": "123"
  }
]
However my API currently only works when it is sent like this:
{
  "key1": "asd",
  "key2":…
         
    
    
        5muqcS7AknXPSt
        
- 75
- 6
                    6
                    
            votes
                
                3 answers
            
        Uploading multiple images and nested json using multipart/form-data in Django REST Framework
I have a problem with parsing request.data in viewset. I have a model that can add multiple images depending on a product.  
I want to split the image from the incoming data, send product data to ProductSerializer, and after that send image to its…
         
    
    
        Metehan Gülaç
        
- 412
- 5
- 15