'Django - TypeError at /api/v1/latest-products/ FieldFile.save() got an unexpected keyword argument 'quality'

I don't know why, but every time I try to go to the API URL, I keep getting this error message, I think the problem is in one of these modules, but I don't know what to change.

models.py module found in the product package

from io import BytesIO
from PIL import Image

from django.core.files import File
from django.db import models

class Category(models.Model):
  name = models.CharField(max_length=255)
  slug = models.SlugField()

  class Meta:
    ordering = ('name',)

  def __str__(self):
    return self.name

  def get_absolute_url(self):
    return f'/{self.slug}'

class Product(models.Model):
  category = models.ForeignKey(Category, related_name='products', on_delete=models.CASCADE)
  name = models.CharField(max_length=255)
  slug = models.SlugField()
  description = models.TextField(blank=True, null=True)
  price = models.DecimalField(max_digits=6, decimal_places=2)
  image = models.ImageField(upload_to='uploads/', blank=True, null=True)
  thumbnail = models.ImageField(upload_to='uploads/', blank=True, null=True)
  date_added = models.DateTimeField(auto_now_add=True)

  class Meta:
    ordering = ('-date_added',)

  def __str__(self):
    return self.name

  def get_absolute_url(self):
    return f'/{self.category.slug}/{self.slug}'

  def get_image(self):
    if self.image:
      return 'http://127.0.0.1:8000' + self.image.url
    return ''

  def get_thumbnail(self):
    if self.thumbnail:
      return 'http://127.0.0.1:8000' + self.thumbnail.url
    else:
      if self.image:
        self.thumbnail = self.make_thumbnail(self.image)
        self.save()

        return 'http://127.0.0.1:8000' + self.thumbnail.url 
      else:
        return ''

  def make_thumbnail(self, image, size=(300,200)):
    img = Image.open(image)
    img.convert('RGB')
    img.thumbnail(size)

    thumb_io = BytesIO()
    image.save(thumb_io, 'JPEG', quality=85)

    thumbnail = File(thumb_io, name=image.name)

    return thumbnail

I think the problem is found in the make_thumbail function or the get_thumbnail function?

serializers.py module found in the product package

from rest_framework import serializers

from .models import Category, Product

class ProductSerializer(serializers.ModelSerializer):
  class Meta:
    model = Product
    fields = (
      "id",
      "name",
      "get_absolute_url",
      "description",
      "price",
      "get_image",
      "get_thumbnail"
    )

views.py module found in the product package

from django.shortcuts import render

from rest_framework.views import APIView
from rest_framework.response import Response

from .models import Product
from .serializers import ProductSerializer

class LatestProductsList(APIView):
  def get(self, request, format=None):
    products = Product.objects.all()[0:4]
    serializer = ProductSerializer(products, many=True)
    return Response(serializer.data)


Solution 1:[1]

Is there a way to download a project from git like torrent downloads?

No

I am open to suggestions of how do you guys fix this issue

Nohow. You have choice:

  • Change your provider and get more stable and fast connection
  • Change your work-style and stop using git in "brainless mode":
    • Git (by design and purpose) not intended to work with big files in repo
    • Store generated from repository-stored sources binary artifacts in the repo is always The Bad Idea (tm)
    • If you must anyway to deal with big files in repo, you have to consider using Git-LFS with a) Git-provider, which support git-lfs b) local fast LFS-storage

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lazy Badger