Questions tagged [django-viewsets]
40 questions
0
votes
1 answer
Getting error "'list' object is not callable" for authentication_classes
I have following method:
class AbcViewSet(viwesets.ModelViewSet):
@action(detail=False, permission_classes=(IsOwnerOrReadOnly,))
@debugger_queries
def get_xyz(self, request, pk=None):
# ...
Inside this method, request.user was…

MsA
- 2,599
- 3
- 22
- 47
0
votes
1 answer
Argument is not getting mapped in REST endpoint method in django
I have following code in my MyModuleViewSet:
class MyModuleViewSet(viewsets.ModelViewSet):
# ...
@action(detail=False, permission_classes=(IsOwnerOrReadOnly,))
@debugger_queries
def my_rest_api(self, request, pk=None):
…

MsA
- 2,599
- 3
- 22
- 47
0
votes
2 answers
i am facing issue to add path to product urls.py file ,i dont know how
```
I am creating CRUD for categories I make a CategoriesViewSet.
on the other hand, I register the router as default in urls.py(Products) for viewset of categories but I don't know how to add a path into the product => urls.py and also the path I…

DarkHorse_906
- 1
- 2
0
votes
2 answers
How to get the authentication information in ModelViewSet?
I am using rest framework with ModelViewSet
class DrawingViewSet(viewsets.ModelViewSet):
queryset = m.Drawing.objects.all()
serializer_class = s.DrawingSerializer
filterset_fields = ['user']
def list(self, request):
queryset…

whitebear
- 11,200
- 24
- 114
- 237
0
votes
2 answers
Django ORM distinct on only a subset of the queryset
Working in Django Rest Framework (DRF), django-filter, and PostgreSQL, and having an issue with one of our endpoints.
Assume the following:
# models.py
class Company(models.Model):
name = models.CharField(max_length=50)
class…

kunambi
- 756
- 1
- 10
- 25
0
votes
0 answers
how to delete an object in modelViewset in DRF?
I am doing a project in DRF and using modelviewset,
my object has two boolean fields and two users as foreign keys,
now i want to show the object only to those users and if both of them set their correspond's boolean attribute to True then the…

ShTurj
- 41
- 1
- 4
0
votes
1 answer
change an object with ModelViewSet
im building a project with DRF and im trying to understand how the modelviewset is working,
im sending a url like this:
localhost/do_somthing/object_id/
and route it with :
router.register('do_somthing', views.do_somthing,…

ShTurj
- 41
- 1
- 4
0
votes
2 answers
Can't authenticate a user in Django rest framework
I'm trying to get data of an authenticated user using the token,
I'm using postman to send a get request and get the data I need but I'm receiving a response
"detail": "Authentication credentials were not provided."
this is the view
`
class…

BoazBitt
- 19
- 3
0
votes
0 answers
call viewset from another app in custom post method in django
How to call viewset from another app with post method in django rest framework?
It's working only with get method but I want to use post method.
@csrf_exempt
@api_view(['POST'])
def new(request):
price =…

Preet
- 1
0
votes
0 answers
django-elasticsearch-dsl-drf filter fields size
There are size options for the Suggester field in django-elasticsearch-dsl-drf . So how do we use the filter extra(size=20) function that we use while writing a query in django-elasticsearch-dsl in django-elasticsearch-dsl-drf view or is there a…

Selim Başpınar
- 11
- 1
0
votes
1 answer
How to fetch rows from a table based on a field which is present in a different table having a foreign key relationship with it?
I have two tables as follows in Django:
Table1:
- id
- name
- address
- state
- short_code
Table2:
- id
- table1_id
- p1, property (searchable field)
Relationship between Table1 and Table2: Table1(1) ->…

NEW VK
- 15
- 6
0
votes
2 answers
How can I join a thrid table to a queryset which already use select_related?
I am working with Django and I need to create an API to retrieve the measures according to the type of sensors, depending of three tables (image of the Schema of my tables)
Measures contains all measures according to an ID of the sensors
Sensors…

pierrot10
- 1
- 3
0
votes
2 answers
How can I get a parameter of an url with django-rest-framework
I am building a map with different station location.
The stations belong to different fields.
I have to show all station and, I have all station of a field.
At some point my api is called
"""Markers API URL Configuration."""
# Maps with Django (2)
#…

pierrot10
- 1
- 3
0
votes
0 answers
How implement Hesh Id in Djnago RESTFRAMEWORK?
I'm trying to hide the id of my objects, but I don't know how to implement it in the correct way. What I did was this:
hashids = Hashids(settings.HASHIDS_SALT, min_length=32)
def parse_result(result) -> Union[int, None]:
if result:
if…

iaggo
- 51
- 5
0
votes
1 answer
Do DRF views use its queryset's object manager?
If I have a custom object manager with a custom create function for a model:
class CustomManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(custom=True)
def create(self):
kwargs["custom"] = True
…

Chris
- 500
- 6
- 25