0

I am not an expert in javascript but I am trying to learn bit by bit.

I am trying to add a search function for my project, so I am starting by sending the item list to JSON using the following:

views.py

class ItemListView(ListView):
    model = Item
    paginate_by = 12
    template_name = "store/product_list.html"
    ordering = ['-timestamp']

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["qs_json"] = json.dumps(list(Item.objects.values()))
        return context

but I keep receiving an error Object of type Decimal is not JSON serializable

My question: Why am I receiving this error although I am following a tutorial and this error didn't show up and how do I fix it?

A_K
  • 731
  • 3
  • 15
  • 40
  • Your **`Item`** model have a ***Decimal*** field and using bare encoders, you can't serialize `Decimal` instances – JPG Jan 02 '21 at 02:09
  • https://docs.djangoproject.com/en/3.1/topics/serialization/#serializing-django-objects – iklinac Jan 02 '21 at 02:10

0 Answers0