Questions tagged [django-viewsets]

40 questions
3
votes
2 answers

How can i set pagination dynamically in Django Rest Framework?

I made an API endpoint using Django Rest Framework, it can be filtered according to two parameters. I'm trying to do the following: when there is no filter, it should retrieve x number of records, while when there is one or more filter, it needs to…
JayK23
  • 287
  • 1
  • 15
  • 49
2
votes
1 answer

ViewSet class variable

Now I have the following logic implemented for a GET request in Django Rest Framework: class SomeViewSet(mixins.ListModelMixin, GenericViewSet): count = None def get_queryset(self): query_set = ... # some_logic …
1
vote
1 answer

How can I modify attributes of objects in a Django queryset for data presentation without modifying the original object?

I want to present a list of objects for which I want to filter/modify one attribute during the presentation of the data. Something close to an annotation, but I did not manage to do it with annotations. These are the models class Airline…
1
vote
2 answers

Django Template is not displaying the table data

I am hoping someone can show me where I am going wrong. In one template I have a table that displays a few rows of data. I want a link in one of the fields to open a separate template for that field. The print commands display the correct…
1
vote
2 answers

Returning queryset that uses a foreign key of a foreign key relationship

It sounds simple enough: get all the Users for a specific Company. But it is complicated by a few things: The User model is extended The model that extends it contains a UUID that uniquely identifies the user throughout various system…
cjones
  • 8,384
  • 17
  • 81
  • 175
1
vote
1 answer

Get all children of self-referencing Django model in nested hierarchy

Introduction We’re currently working on a Django REST Framework project. It connects to a Postgres database that holds some hierarchical (tree structure) data, that goes a number of levels deep. We should offer an endpoint for GET requests that…
1
vote
3 answers

permission to class some fields of ViewSet method Django rest framework

I want AllowAny permission only for the retrieve function. In my ViewSets. class PostLanguageViewSet(viewsets.ViewSet): permission_classes = (permissions.AllowAny,) permission_classes_per_method = { "retrieve": permission_classes …
1
vote
1 answer

How can I select an instance of django model to update the info inside that model or related models?

I have basically three models. class Users(models.Model): name = models.CharField(max_length=100) ... class Portfolio(models.Model): name = models.CharField(max_length=50) user = models.ForeignKey(Users, on_delete=models.CASCADE,…
1
vote
1 answer

How to inherit Generic Filtering in extra action

I want to inherit Generic Filtering include (filterset_fields, search_fields, ordering_fields in extra action sold. So how to do it, and any way better for this case? class ApartmentViewset(viewsets.ModelViewSet): queryset =…
Kev
  • 315
  • 1
  • 4
  • 11
1
vote
1 answer

Getting request.data as an empty dictionary

I have a viewset like the follwing class DummyViewSet: def create(self, request, *args, **kwargs): variable_a = 5 return another_api_end_point(request, variable_a) ---> request.data: {"a":"value1", "b":…
1
vote
1 answer

Cannot get values from request in Django - Empty QueryDict

I’m new to ViewSets and am trying to get the values sent from the front-end fetch method to Django’s request object in the create function. I don’t know whether it’s just a simple syntax error or whether the data isn’t being sent properly from the…
user8758206
  • 2,106
  • 4
  • 22
  • 45
1
vote
0 answers

How to map a patch method over an action with detail=False in Django Rest Framework

I am building an API with Django and Django Rest Framework I have the following endpoint: host/products/ pointing to a ModelViewSet, so I have a CRUD working for the specified model. Also, I define an extra action for a nested model called config…
1
vote
1 answer

How to use different lookup field in each request of one class

Want access the different request by using the different lookup fields. I have use the simplerouter in router and ModelViewSet in views of the django rest framework. Example of the expected use case: url to perform update - /user/{id}/ url to…
0
votes
1 answer

Add a django-filter to allow contains, match (exact) and exclude certain text

Based on the documentation for django-filters to use excludes I have a filter that allows custom filtering for multiple fields to search to match text (exact or contains). I'm trying to extend this to allow the text to be excluded from the search.…
Loser Coder
  • 2,338
  • 8
  • 42
  • 66
0
votes
0 answers

Call a viewset in another viewset with POST method

I want to call a function of a viewset in another viewset, with POST method. I don't known how to do that :(, I've this error "GET method not allowed" : url from initial AccessViewset : access_level_add = accesslevel.AccessViewSet.as_view({"post":…
fabrice
  • 1,399
  • 1
  • 15
  • 27
1
2 3