Questions tagged [django-rest-viewsets]

362 questions
1
vote
2 answers

Django password storage

I'm having some trouble storing passwords with Django REST Framework. Basically, the password of the superuser was stored correctly (it looks like this: pbkdf2_sha256$320000$iSRRmEm7YbZHoYzd4wJt2v$Yht0x74n4DSDvM0JjnzddSPU8sp0ahmog0ZAsdT4j84=).…
1
vote
1 answer

How to use make delete request of generic viewset without sending the pk

I am using django in the backend and react native in the frontend, I have a generic viewset with destroy, create mixins. In my use case, I make a post request when the user is logged in and then delete the same instance when he logged out. The…
1
vote
1 answer

Django Rest Frame give 404 not found

When I hit the URL doctor/56b63b2d-11c4-4f0c-be7c-0b0348c487fd/ I get the detail not found I tried every solution but still it' not work error : - "GET /doctor/56b63b2d-11c4-4f0c-be7c-0b0348c487fd/ HTTP/1.1" 404 11332 class…
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
1 answer

Detail viewset for product in django rest framework

I need to get just one product object in my VeiwSet based on a given slug, I looked into the docs, but I can't find any solution to this problem. I need to get the slug from the url path aswell, but I don't know how to do it too. Obviously the code…
1
vote
1 answer

Is there a way to dynamically specify a queryset for nested relationship (nested serializer class) in django rest framework

Suppose we have two models: class Chapter(models.Model): title = models.CharField(max_length=128) owner = models.ForeignKey(User, on_delete=models.CASCADE) class Post(models.Model): title = models.CharField(max_length=128) body =…
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…
1
vote
0 answers

Filtering the fields listed by the CreateModelMixin based on ForeignKey in Django Rest Framework

Hello, I am starting to learn Django Rest Framework, i have come across a problem, that i couldn't solve, that is described below: I have defined three models in models.py: Endpoint Model class Endpoint(models.Model): name =…
1
vote
1 answer

How to serialize the foreign key field in django rest framework

I work on a project with DRF where I'm getting serializer data as follows which is absolutely fine: { "message": "Updated Successfully", "status": 200, "errors": {}, "data": { "id": 8, "user": 2, "item": 1, …
1
vote
1 answer

Setting a ForeignKey to the current logged in user | Django Rest framework ViewSets

I am building a REST API with Django Rest Framework's ViewSets and have come across a problem. When using a POST request on my API, I can't easily insert the current logged in user into the model. The model I am serializing is as follows: from…
1
vote
1 answer

DjangoRestFramework : Create separate URLs for separate functions of ModelViewSet

I have a ModelViewset in Django Rest Framework : class UserViewset(viewsets.ModelViewSet): queryset = models.User serializer_class = serializers.User Its router : router = routers.DefaultRouter() router.register(r'user',…
1
vote
1 answer

django rest framework serializer saving field value as empty strings, but no errors

django rest framework serializer saving field value as empty strings, but no errors views.py from django.shortcuts import render from rest_framework import viewsets from rest_framework.authentication import TokenAuthentication from .models import…
1
vote
1 answer

How to use query params to filter objects in DRF?

I try to query a Course by its own field "name" instead of pk. And what should be the path when querying this? All basic Cruds and query by pk works fine with this code. Here I have all related files attached: models.py from django.db import…
1
vote
1 answer

ID parameter in Django REST API URL

I have two models: Article Comment Comments are connected to Article with ForeingKey. I want to create an endpoint like: {GET} /article/97/comments # get all comments of article (id:97) {POST} /article/97/comments # create an…
1
vote
0 answers

Can I create a filter for all paramters in a model without having to write each one in the queryset?

I have a model like this: class Item(models.Model): """Class to represent an item...""" label = models.TextField(null=True) photo = models.ImageField(null=True, upload_to='item_images/%Y/%m/%d/') name = models.TextField() …