Questions tagged [django-rest-viewsets]
362 questions
1
vote
1 answer
Get Authenticated user on many=True serializer Viewset
I'm writing a rest api using Django Rest Framework, I have an endpoint to create objects on POST method and this method is overridden in order to allow bulk adding. However, the object is an "intermediate table" between Pacient and Symptoms and in…

Luc
- 393
- 7
- 19
1
vote
1 answer
How to retrieve profile of my user details into profile page of user
My view of user profile
@api_view(['GET'])
@permission_classes((IsAuthenticated, ))
def user_profile(request,id):
try:
up = get_object_or_404(User_Profile, pk=id)
except User_Profile.DoesNotExist:
return…

Ganesh Kuikel
- 25
- 6
1
vote
2 answers
How can custom values be passed from a DRF ModelViewSet to a permissions class?
I've set up a custom permissions class to be reused from multiple views, in an app where some users have ownership-like rights on behalf of other users:
class IsOwnerLike(permissions.BasePermission):
def has_permission(self, request, view):
…

Adam Lombard
- 324
- 2
- 7
1
vote
1 answer
Original exception text was: 'QuerySet' object has no attribute 'client'
I got AttributeError when attempting to get a value for field client on serializer ClientSerializer.
The serializer field might be named incorrectly and not match any attribute or key on the QuerySet instance.
models.py
class Box(models.Model):
…

guilherme torello
- 13
- 1
- 4
1
vote
1 answer
How to get data from ModelViewSet in DRF without calling an API call
I'm going to convert all my APIs into gRPC calls. At the moment I was able to transfer all the ViewSet into gRPC(sample code added end of this question). But ModelViewSet, it get an error like this.
Traceback (most recent call last):
File…

tikirin tukurun
- 121
- 4
- 9
1
vote
1 answer
Filtering in Django ModelViewSet
I don't think I'm doing this correctly. What I'm trying to do is prevent data from being returned if it doesn't match my criteria. Here are the criteria:
User should be able to see the project if:
If the object is private and they are the owner
--…

Justin Boucher
- 343
- 4
- 17
1
vote
2 answers
Passing The ID of a Field in another Field of the same model Django
Hello, I am trying to pass the ID of a Model in an Image Field URL(upload_to) and then access it Through a URL unique to The instance.
Here's What I did (Amature);
class User(models.Model):
serial = models.AutoField(primary_key=True)
profile…

ax39T-Venom
- 32
- 1
- 5
1
vote
1 answer
DRF ModelViewSet queryset return results that their date is greater than or equal to today
I am using Django Rest Framework.
In the queryset I'm trying to filter my objects based on IF their Date is greater than or equal to today. Like so:
class DateViewSet(viewsets.ModelViewSet):
"""
API Endpoint to retrieve all dates after…

Tony
- 2,382
- 7
- 32
- 51
1
vote
0 answers
Is there any alternative to get_queryset() method to capture query parameter in Django ViewSet?
what i am using is :
class SomethingViewSet(viewset.ModelviewSet):
def get_queryset(self):
id=self.request.query_params.get('id')
Is there any alternative to capture query params.

Shubham Kumar
- 105
- 1
- 1
- 8
1
vote
1 answer
Using custom query to return JSON in Django Rest Framework
I started to work with Django rest and I want to know:
Can I make a View or something else to make a custom query and return a JSON?

Reinaldo Peres
- 303
- 2
- 5
- 14
1
vote
2 answers
Invoke function after all methods Django Rest Framework ModelViewSet
I would like to invoke a function after all methods in a ModelViewSet. The function itself will be used as an external event log. So the response from the views would not be modified. I was not able to figureout how to achieve this. My ModelViewSet…

ssm
- 620
- 6
- 24
1
vote
1 answer
How to get relative url of ImageField when using ModelViewSet in django rest framework?
I am getting an absolute URL of an ImageField when using ModelViewSet in the Django rest framework. When I am using a development server, its returning http://localhost:8000/media/abc.png and this is fine for me. But when I am using the nginx…

Rajesh Samui
- 167
- 1
- 2
- 12
1
vote
1 answer
How to add a custom action function using Django DRF viewset.Viewsets?
I have a viewset that I created an @action decorated function.
class StoreOffersViewSet(viewsets.ViewSet):
"""Viewset for yoga stuff."""
@action(detail=False, methods=['put'], name='yoga update')
def update_yoga(self, request):
…

user875139
- 1,599
- 4
- 23
- 44
1
vote
1 answer
Returning the current user id along with the token when login using Token Authentication in django rest framework
I am using JWT token for login authentication.
When the user logs in, it returns a token.
how can i get the user id of the logged in user along with the token?
I have tried it by using request.user. it it return AnonymousUser.
class…

Jinu Joseph
- 542
- 1
- 4
- 17
1
vote
1 answer
How to add the current user to a many-to-many field when creating via a viewset?
I have a Django project which has "workspaces", and users can belong to multiple workspaces, so there's a many-to-many relationship between the users and the workspaces.
Now, everything else works fine so far, but I'm having trouble adding the…

manabreak
- 5,415
- 7
- 39
- 96