Questions tagged [django-rest-viewsets]

362 questions
0
votes
2 answers

What determines what fields can be updated in DjangoRestFramework

I currently have a serializer with the following fields class Meta: model = Asset fields = ('id', 'uuid', 'asset_category', 'asset_sub_category', 'make_label', 'asset_code', 'serial_number', 'model_number', …
E_K
  • 2,159
  • 23
  • 39
0
votes
0 answers

Handling viewset that has a serializer with multiple foreignkeys

I have this serializer: class ReviewSerializer(serializers.ModelSerializer): user = UserSerializer(read_only=True) class Meta: model = Review fields = ('pk', 'title', 'user', 'movie', 'timestamp', 'review_text',) I want to…
yierstem
  • 1,933
  • 5
  • 21
  • 42
0
votes
0 answers

AttributeError at /api/list/ 'NoneType' object has no attribute 'delete'

class StatusListSearchApi(mixins.CreateModelMixin, mixins.RetrieveModelMixin, mixins.UpdateModelMixin, mixins.DestroyModelMixin, ListAPIView): # queryset=status.objects.all() serializer_class=statusSerializer …
0
votes
1 answer

View Set - filter objects

I have a problem with filtering objects in View Set... I am trying to show objects only where field 'point' is null. I always get error: NameError: name 'null' is not defined Could you please HELP ME ? My code: class…
RalGoX
  • 35
  • 1
  • 8
0
votes
1 answer

Related object reference does not work without importing the related model itself

I have 2 models in my app - In models/parent.py I have - from django.db import models class Parent(models.Model): class Meta: db_table = "parent_table" start_date = models.DateField() end_date =…
0
votes
2 answers

Django Viewset returning different data between shell/tests and actual requests

Simplified model structure (I'm leaving out important bits, obviously, there are good reasons these are in different models): class Contact(models.Model): receive_marketing = models.DateTimeField(null=True, blank=True) class…
0
votes
0 answers

Django Rest Framework Post method not allowed for a Route

I'm writing a rest API using Django rest framework, I have setup viewsets, serializers and routes in their corresponding files.But when I send a post request to a route it returns POST method not allowed. Here's what i have done: viewsets.py class…
Abdul Rehman
  • 5,326
  • 9
  • 77
  • 150
0
votes
1 answer

Count the number of rows in a Django database : AttributeError

I have database created by Django model, where idRecruteur is the fields of the table Offre. I need to count the number of rows where idRecruteur = 1. This is my "Offre" table code: @python_2_unicode_compatible class Offre(models.Model): …
ccr0x
  • 51
  • 5
0
votes
1 answer

Saving two related models via one serializer and passing the first id to the second as a foreign key in django rest framework?

I have a JourneySchedule model which stores depart and return journeys: class JouaneySchedule(models.Model): Owner = models.ForeignKey('Profile', on_delete=models.PROTECT) ReturnOf = models.ForeignKey('self', on_delete=models.CASCADE,…
0
votes
2 answers

DRF PATCH method, got all values at type of string in request.data

I am sending axios.patch request with form-data in vue axios.patch(`${API_BASE}/products/${id}/`, data, { headers: { 'Content-Type': 'multipart/form-data' } and calling Django ModelViewset partial update class…
0
votes
1 answer

Serializer for inherited model

I have following models declared: class Parent(models.Model): active = models.BooleanField(default=False) class Child(Parent) name = models.CharField(max_length=100, unique=True) and serializer: class…
0
votes
1 answer

ValueError: Cannot assign "u'http://localhost:8000/players/1/'": "Game.referee" must be a "User" instance

I understand what this error is saying, just not understanding how to pass user instance in a request(postman). Following is my model. class Game(models.Model): referee = models.ForeignKey(User, on_delete=models.CASCADE, related_name='referee') …
Kishor Pawar
  • 3,386
  • 3
  • 28
  • 61
0
votes
1 answer

Django rest ModelViewSet serializer create fails

I have two models with following relationship: class Library(models.Model): library_id = models.AutoField(primary_key=True) name = models.CharField(max_length=30) ... class Reader(models.Model): user = models.OneToOneField(User) …
Thinker
  • 5,326
  • 13
  • 61
  • 137
0
votes
1 answer

Filter ranges using Django Backend filter?

I am working on project using django rest framework in which i have to filter different parameters given by user.I am using django Filter backend. Here is my code: class FilterViewSet(viewsets.ModelViewSet): serializer_class =…
0
votes
1 answer

DJango REST Framework: add additional functionality to ModelViewSet create method

I am attempting to add to the django server additional functionality upon different host requests. To do do so, I overridden the ModelViewSet functions with thought to add functionality within those functions. What I saw is that when setting a…