Python Forum
Django "Unexpected Keyword Argument 'min_value'"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Django "Unexpected Keyword Argument 'min_value'"
#1
Hi All,

I'm currently learning the basic methods of DjangoRESTFramework. It's the first time I've learned how to make and use an API. I'm just playing around, pretending that it's an API for scores for staff members in a company.

I'm having an error when I submit a POST request to the server. I can't for the life of me understand why, although I assume it's some small syntactical error or just missing a line that I can't debug myself because it's all new to me at the moment.

I've created a token for a superuser, and I'm posting this token to the server from Insomnia, along with "staff_id", 3, and "score", "5" as the query parameters.

It comes up with a 500 error, and says:

Error:
... Exception Type: TypeError Exception Value: Field.__init__() got an unexpected keyword argument 'min_value' ...
This is the relevant code:

models.py
from django.db import models
from django.contrib.auth.models import User

class Score(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    staff_id = models.SmallIntegerField
    score = models.SmallIntegerField
views.py
from rest_framework import generics
from rest_framework.permissions import IsAuthenticated
from .models import Score
from .serializers import ScoreSerializer

class ScoreView(generics.ListCreateAPIView):
    queryset = Score.objects.all()
    serializer_class = ScoreSerializer

    def get_permissions(self):
        if(self.request.method=='GET'):
            return []
        
        return [IsAuthenticated()]
serializers.py
from rest_framework import serializers
from .models import Score
from rest_framework.validators import UniqueTogetherValidator
from django.contrib.auth.models import User

class ScoreSerializer (serializers.ModelSerializer):
    user = serializers.PrimaryKeyRelatedField(
            queryset=User.objects.all(),
            default=serializers.CurrentUserDefault()
    )

    class Meta():
        model = Score
        fields = ['user', 'staff_id', 'score']

        validators = [
            UniqueTogetherValidator(
                queryset=Score.objects.all(),
                fields=['user', 'staff_id']
            )
        ]

        extra_kwargs = {
            'score': {'min_value': 0, 'max_value': 10},
        }
If I remove the extra kwargs and just try posting a staff_id and score of whatever numbers I choose, it just comes up with a 400 bad request. Is it that I need some POST function in the views.py?

Any help would be appreciated. Hopefully I've formatted the BBCode properly...

Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Find a specific keyword after another keyword and change the output sgtmcc 5 854 Oct-05-2023, 07:41 PM
Last Post: deanhystad
  "unexpected keyword arg" when initializing my subclasses Phaze90 3 3,178 Nov-25-2022, 07:39 PM
Last Post: Gribouillis
  i want to use type= as a function/method keyword argument Skaperen 9 1,884 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  TypeError: __init__() got an unexpected keyword argument 'value' Anldra12 7 22,696 May-11-2021, 06:35 PM
Last Post: deanhystad
  TypeError: coerce_kw_type() got an unexpected keyword argument 'dest' juniii 1 2,439 Apr-24-2020, 01:53 PM
Last Post: Jeff900
  SyntaxError: positional argument follows keyword argument syd_jat 3 5,851 Mar-03-2020, 08:34 AM
Last Post: buran
  __call__() got an unexpected keyword argument 'text' saba_keon 5 9,384 Apr-07-2018, 11:11 PM
Last Post: nilamo
  Unexpected argument jstockton 10 16,440 Feb-21-2017, 02:30 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020