Questions tagged [django-rest-viewsets]

362 questions
0
votes
0 answers

Django rest framework use serializer_class in viewset @detail_route

I'm using viewsets with a lot of @detail_route and @list_route. In normal viewsets i use serializer_class and then some validation in serializer but in @detail_route I'm creating serializer in view and check validation here - I know its bad. My…
Thaian
  • 1,215
  • 2
  • 20
  • 30
0
votes
3 answers

What happens if queryset and get_queryset are both defined on a Django ViewSet that inherits from GenericViewSet

I've inherited some Django code and I am struggling to work out what the previous developers have intended with their code. There is a ViewSet which is configured, which inherits from GenericViewSet. In the class it defines a queryset variable but…
Matt Fellows
  • 6,512
  • 4
  • 35
  • 57
0
votes
1 answer

How to create / update 2 objects [Django Rest Framework]

I'm new to django rest framework and I'm trying to create / update 2 objects in the same request: class PessoaSerializer(serializers.ModelSerializer): user = UserSerializer(required=False) class Meta: model = Pessoa fields =…
0
votes
0 answers

Unable to see viewset with update method in API page

I have few Viewsets inheriting viewsets.ViewSet and contain override list() method. I have registered all these Viewsets on API page. Now I have one more viewset which override update() but I am not able to see it on API page. This is my code: class…
Niyojan
  • 544
  • 1
  • 6
  • 23
0
votes
1 answer

How do I upload an image via Django Rest Framework?

Here is my my model containing ImageField: class Profile(models.Model): user = models.OneToOneField(User) new_article_notifications_enabled = models.BooleanField(default=False) new_comment_notifications_enabled =…
Vassily
  • 5,263
  • 4
  • 33
  • 63
0
votes
1 answer

Call view from another view

I have a viewset with one of the views as: @list_route(methods=["get"], url_path="special") def special(): pass And I call this view from another view like: view_fn = viewset.as_view({'get': 'list'}) response = view_fn(request) But it does not…
user4848830
  • 779
  • 12
  • 22
0
votes
0 answers

Can I use a django rest framework ModelViewSet to render its form and pass the list json to a regular view?

I want to use the rest framework api to render the json data from the list method and the form from the post in a template. I have been searching in the rest-framework docs for the renderer clases, Html rendering and form rendering but came to no…
0
votes
2 answers

django rest framework - filtering against date query parameter

In my view I'm receiving date parameter and I'm filtering against it so I could show my contact for today, and it goes something like this: filter_date = self.request.query_params.get('filter_date', None) for queryset in contact_lead: if…
0
votes
1 answer

Django filter on attribute with two values, preferring the result of one

This is kind of a weird question, so sorry in advance. I have a model in Django Rest that looks like this: class BaseModel(models.Model): created_date = models.DateTimeField(auto_now_add=True) modified_date =…
0
votes
0 answers

DjangoRest - It is possible to define multiple create(self, request) in ModelViewSet

I have a project which need to perform different create processes of the same Model. We can achieved this one by creating multiple ModelViewSet. class AnimalViewSet(viewsets.ModelViewSet): queryset = Animal.objects.all() serializer_class =…
Shift 'n Tab
  • 8,808
  • 12
  • 73
  • 117
-1
votes
1 answer

get and delete in Django framework

i want to build a ModelViewSet class that recive an id from url for instance localhost/id and based on that id i can either show the object with matching id or delete the object but im having trouble passing the id in the url my view is like…
-1
votes
2 answers

How to break multiple if statements?

I have a permission class for my viewset. But it has multiple if statements and the if statements can be added others as well if some action added inside viewset. So how can I optimize my code here for better performance ? def has_permission(self,…
D_P
  • 802
  • 10
  • 32
-1
votes
1 answer

Django restframework generic viewset not working with get and get detail views with the same url_path and url_name

How can I make two views in a DRF Generic viewset use the same url_paths and url_names provided the make use of the same or different methods but different details value, eg must can both be Get methods but would have details=True and details=False…
-1
votes
4 answers

Break up field into its own serializer in Django Rest Framework

Let's say I have simple Product Django model: class Product: name = models.CharField(max_length=255, unique=True) created_on = models.DateField() I'm using Django Rest Framework to serialize this model. I'd like to break up created_on into…
Johnny Metz
  • 5,977
  • 18
  • 82
  • 146
-2
votes
1 answer

Getting localhost for next page url in production

hlo, I have deployed a Django rest app in production. When I call a list API there is a pagination, and I am getting localhost for next page URL. I am using GenericViewSet and LimitOffsetPagination for pagination. My app is running in docker…
1 2 3
24
25