Questions tagged [django-rest-viewsets]

362 questions
0
votes
1 answer

Django - BaseSerializer.is_valid() missing 1 required positional argument: 'self'

I am creating a base viewset class and trying to use it in two classes. The viewset has a create method which uses the get_serializer_class() to get the serialzer and creates the object. But the is_valid() throws error TypeError:…
0
votes
2 answers

DRF: How to pass extra context data to serializers

I was searching the net and found the similar problem but it doesn't work in my case, Idk why. I try to put some extra data to context in serializer, but get only 3 default fields: request, view and format and no mention for my custom data. My…
0
votes
1 answer

Deploying Django API on Heroku- after changing DEBUG = False (in settings.py) and deploying my app, URLconf defined in URLS.PY are not listed

I have created Django API with three apps (users, task, house) with with help of routers show data in ViewSets. Some of these routers have to register multiple ViewSets. When testing endpoints both locally and on remote server (Heroku gunicorn) they…
Sanna
  • 1
  • 1
0
votes
1 answer

How to Use Viewsets and Serializers in pytest==7.0.1 Parametrize in Testing djangorestframework==3.13.1 get_serializer() and get_permission()?

I am using a Django Project Template from here. I am testing my serializers and permission in every viewset my app has. I want to use parametrize from pytest to reduce the lines I need to write tests to each serializers and viewset. I have 10…
0
votes
1 answer

Django rest setting the one to one relation creating an post method

I am new to django,I have created the models with OnetoOne relationship , I have user table and i have onetoone relation with storyboard library table, the issue is when i am creating an storyboardlibraby object , i need to save the user objectin…
0
votes
0 answers

How to create a Django Rest API that can accept and return a file without a model

I want to create an API view without a model that accepts an excel file, allows me to manipulate the file, then returns the manipulated file back. The reason I don't want to use a model is because I don't want the excel file…
meg hidey
  • 192
  • 4
  • 15
0
votes
3 answers

Filtering by Foreign Key in ViewSet, django-rest-framework

I want my api to return certain objects from a database based on the foreign key retrieved from the url path. If my url looks like api/get-club-players/1 I want every player object with matching club id (in this case club.id == 1). I'm pasting my…
0
votes
1 answer

Django Rest Framework ModelViewSet ManyToMany Field override partial_update Method is not working update_or_create

I have a question here I have two models Tag Model class Tag(models.Model): creator = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='author') name = models.CharField(max_length=100) def…
0
votes
1 answer

Want to Create a model object with the instance of Another object from single serializer: Django - Rest API - Generic Views

I have a User model and a Teacher model as below User model must be created first and Teacher model is created with User as an object (ForeignKey). User Model class User(AbstractUser): ''' Class to store details of Users Attribs: username…
0
votes
1 answer

making an api to show the books of an auther in django rest framework

I have two models in my project: Author and Book. Each book has a foreignkey that points to the author of the book. I want to write an api which retrieves and instance of an Author and shows the details of that specific person. The problem is that I…
0
votes
1 answer

How to implement registration and login logics as an API using ViewSet instead of generic views in Django Rest Framework

I am new to viewset when using Django Rest Framework to create registration and login logics as an API using ViewSet instead of generic views, and exposing resources to a React standalone frontend app on a diffrent port. In a previous project where…
Himmels DJ
  • 395
  • 5
  • 20
0
votes
1 answer

How to make the django rest framework POST button work?

I have a model like this: class Ad(models.Model) : title = models.CharField( max_length=200, validators=[MinLengthValidator(2, "Title must be greater than 2 characters")] ) price =…
BoumTAC
  • 3,531
  • 6
  • 32
  • 44
0
votes
1 answer

username with `james i. adams` not accepted with django routers

I have registered routers for user model, which has viewset that has lookup_url as username. The username james adams is accepted by the router, but getting below error for james i. adams django.urls.exceptions.NoReverseMatch: Reverse for…
0
votes
1 answer

Django restframework viewset serializer KeyError

I try to POST request but I got KeyError. Exception Location: C:\github\dj-postgres-heroku\get_staff\serializers.py, line 32, in create Here is error location and that line is this. def create(self, validated_data): **profile_data =…
0
votes
2 answers

How to force a value when creating with django-rest-framework ModelViewSet?

I have an api where users can create different objects. If the user is part of the staff, he can create the object with all the values he wants. However, if the user is not part of the staff, I want to force the value of a particular field. I added…
darkvodka
  • 303
  • 1
  • 3
  • 11