Questions tagged [django-rest-viewsets]
362 questions
0
votes
0 answers
How to set lookup_field of GenericViewSet with JSONfield key?
How do I set the lookup_field with a key in JSONField model?
The model:
exchange = models.ForeignKey(StockExchange, on_delete=models.CASCADE, related_name='tickers')
fundamentals = models.JSONField(null=True, blank=True)
The viewset:
class…

antimatter7
- 61
- 1
- 2
- 4
0
votes
1 answer
Calling a DRF View from another View
I have a User Model Viewset that adds users to my Django Rest Framework application (VueJS -> DRF -> PostGres).
I have another ModelViewSet for an activity log that has entries when users get credit for doing training, etc.
I ran into an issue where…

Bring Coffee Bring Beer
- 1,035
- 3
- 11
- 19
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
1 answer
How do I use permission_classes in a custom method of a Viewset in DjangoRestFramework?
Suppose that I have a Viewset named UserViewset, and I have assigned IsAuthenticated permission to UserViewset Viewset. Now, I want to create a normal method (not an action method), and I want to assign another permission to that method which is…

Khubaib Khawar
- 1
- 2
0
votes
0 answers
Good practice to use a single update view function for multiple tasks?
I was wondering whether it is considered DRY and good practice to aggregate many small actions such as updating first name, last name, email, etc... using the same update method? First, I thought that it was a good idea because my validation is…

lays
- 158
- 1
- 1
- 7
0
votes
1 answer
Why does a retrieve request end up calling `get_queryset( )`?
The DRF helps you make a simple API that exposes an endpoint for listings of an object and the details for a specific object.
My viewset looks like this:
class UserViewSet(ModelViewSet):
serializer_class = someSerializer
queryset =…

zsega
- 113
- 7
0
votes
1 answer
Is there a way to have an action with detail = True inside another action with detail = True in Django rest?
My user model has a Many to one relationship to a Clothes model and inside my User viewset I created an extra action to list the Clothes instances in relation to a specific user
@action(detail=True, methods=['get'],…

Pefori
- 39
- 5
0
votes
1 answer
Call is-valid when pagination is applied to data in DRF
I have a ModelViewSet and I am using ModelSerializer. I am also using Pagination that is from django.core.
My views code snippet that works:
page_number = request.data.get("page")
data = Model.objects.filter()
paginator = Paginator(data, 100)
page =…

Lax_Sam
- 1,099
- 2
- 14
- 32
0
votes
1 answer
Viewsets: the input field for Tag object does not appear, can not create Dot object with post method
Not sure of the reason but maybe I have passed in a wrong way request to the context in views.py, In views.py where post method 'tag' input field is missing
class Dot(models.Model):
user = models.ForeignKey(
…

kubaSpolsky
- 357
- 2
- 10
0
votes
0 answers
Django path didn’t match any of these when adding query param to the endpoint
I am using django 4.1
I have a product model
class Product(models.Model):
product_id = models.CharField(
blank=False,
null=False,
max_length=50,
verbose_name="stock ID",
)
name =…

Menna Magdy
- 355
- 1
- 2
- 14
0
votes
1 answer
add if does not already exist
Hello every one I'm trying to write a View Set API, that let you add course obj to your favorite list,but before adding check it if user added course already don't let user add again and if user didn't add so let user add it to the list,
but I…

Ashti Nematian
- 43
- 8
0
votes
1 answer
Manytomay field is None or can't call field in a view in django
I have a problem in my code,I'm Trying to querying to my course model, I have a many to may field of course in user model,now I need to query to course model that course title or id is equal to user's courses
My course model is:
class…

Ashti Nematian
- 43
- 8
0
votes
2 answers
Querying for models based on time range in Django REST Framework
I have a DB with models that each have two timestamps.
class Timespan(models.Model):
name = models.CharField(null=False)
start_time = models.DateTimeField(null=False)
end_time = models.DateTimeField(null=False)
I want to be able to…

Brian C
- 1,333
- 3
- 19
- 36
0
votes
1 answer
Getting error while partial update data in drf
Hi Everyone i am creating api for partially update record, but getting error [patch() missing 1 required positional argument: 'id'], please help me out
views.py
class GmsGarageViewset(APIView):
def patch(self,request,id):
…

Karishma Upadhyay
- 125
- 1
- 9