title: List of products from the given category
body: <p>I'm just getting started and I have a problem. I want to get in<br>
  SlugView a list of all products in the given category ('slug').</p>
  
  <p>models.py</p>
  
  <pre><code>class Category(models.Model):
      category_name = models.CharField(max_length=64)
      slug = models.CharField(max_length=64, unique=True)
  
  class Product(models.Model):
      name = models.CharField(max_length=128)
      description = models.TextField()
      price = models.FloatField()
      vat = models.FloatField(choices=VAT)
      stock = models.IntegerField()
      categories = models.ManyToManyField(Category)
  
      @property
      def name(self):
          return "Nazwa: {}, cena: {}".format(self.name, self.price)
  
      def __str__(self):
          return self.name
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>class SlugView(View):
      def get(self, request, slug):
          category = Category.objects.filter(slug=slug)
          return render(request,'exercises/slug.html', {'products': products})
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code> re_path(r'categories/(?P&lt;slug&gt;\w+)', SlugView.as_view(), name = "slug")
  </code></pre>
  
  <p>Bug list:
  '''
      Starting development server at <a href="http://127.0.0.1:8000/" rel="nofollow noreferrer">http://127.0.0.1:8000/</a>
      Quit the server with CONTROL-C.
      [05/Feb/2020 09:46:37] "GET / HTTP/1.1" 200 965
      [05/Feb/2020 09:46:42] "GET / HTTP/1.1" 200 965
      [05/Feb/2020 09:46:45] "GET /categories HTTP/1.1" 200 997
      Internal Server Error: /categories/1234D
      Traceback (most recent call last):
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 828, in _resolve_lookup
          current = current[bit]
      TypeError: 'Product' object is not subscriptable</p>
  
  <pre><code>During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
      response = get_response(request)
    File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
      response = self.process_exception_by_middleware(e, request)
    File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 71, in view
      return self.dispatch(request, *args, **kwargs)
    File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 97, in dispatch
      return handler(request, *args, **kwargs)
    File "/home/marekk/Pulpit/kurs/django-za2/WAR_PYT_W_11_Zaawansowane_Django/3_Django/coderslab/exercises/views.py", line 30, in get
          return render(request,'exercises/slug.html', {'products': products})
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/shortcuts.py", line 19, in render
          content = loader.render_to_string(template_name, context, request, using=using)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/loader.py", line 62, in render_to_string
          return template.render(context, request)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/backends/django.py", line 61, in render
          return self.template.render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 171, in render
          return self._render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
          return self.nodelist.render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 936, in render
          bit = node.render_annotated(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 903, in render_annotated
          return self.render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/loader_tags.py", line 150, in render
          return compiled_parent._render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
          return self.nodelist.render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 936, in render
          bit = node.render_annotated(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 903, in render_annotated
          return self.render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/loader_tags.py", line 62, in render
          result = block.nodelist.render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 936, in render
          bit = node.render_annotated(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 903, in render_annotated
          return self.render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/loader_tags.py", line 62, in render
          result = block.nodelist.render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 936, in render
          bit = node.render_annotated(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 903, in render_annotated
          return self.render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/defaulttags.py", line 209, in render
          nodelist.append(node.render_annotated(context))
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 903, in render_annotated
          return self.render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/loader_tags.py", line 62, in render
          result = block.nodelist.render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 936, in render
          bit = node.render_annotated(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 903, in render_annotated
          return self.render(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 986, in render
          output = self.filter_expression.resolve(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 670, in resolve
          obj = self.var.resolve(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 795, in resolve
          value = self._resolve_lookup(context)
        File "/home/marekk/Pulpit/kurs/Django_cwicz/venv/lib/python3.6/site-packages/django/template/base.py", line 836, in _resolve_lookup
          current = getattr(current, bit)
        File "/home/marekk/Pulpit/kurs/django-za2/WAR_PYT_W_11_Zaawansowane_Django/3_Django/coderslab/exercises/models.py", line 88, in name
          return "Nazwa: {}, cena: {}".format(self.name, self.price)
        File "/home/marekk/Pulpit/kurs/django-za2/WAR_PYT_W_11_Zaawansowane_Django/3_Django/coderslab/exercises/models.py", line 88, in name
          return "Nazwa: {}, cena: {}".format(self.name, self.price)
        File "/home/marekk/Pulpit/kurs/django-za2/WAR_PYT_W_11_Zaawansowane_Django/3_Django/coderslab/exercises/models.py", line 88, in name
          return "Nazwa: {}, cena: {}".format(self.name, self.price)
        [Previous line repeated 449 more times]
      RecursionError: maximum recursion depth exceeded while calling a Python object
      [05/Feb/2020 09:46:49] "GET /categories/1234D HTTP/1.1" 500 1694912
  </code></pre>
  
  <p>'''</p>
  
  <p>Here you are templates.</p>
  
  <p>template "slug.html"
  '''</p>
  
  <pre><code>{% extends 'exercises/base.html' %}
  
  {% block page_title %}
              &lt;h1&gt;Sklep internetowy OLABOGA.&lt;/h1&gt;
        {% endblock %}
  
  {% block content_title %}&lt;h2&gt;Produkty w kategorii:&lt;/h2&gt;
   {% endblock %}
  
  {% block content %}
      &lt;ul&gt;
          {% for product in products %}
              {% block element %}
                  &lt;li&gt;&lt;a href='/{% block link %}product{% endblock %}/
                      {{ product.name }}'&gt;{{ product.name }}&lt;/a&gt;&lt;/li&gt;
              {% endblock %}
          {% endfor %}
      &lt;/ul&gt;
  {% endblock %}
  </code></pre>
  
  <p>'''</p>
  
  <p>template "base.html"
  '''</p>
  
  <pre><code>{% load static %}
  &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Title&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      {% block logo %}
          &lt;img src="{% static 'images/logo.png' %}" alt="Tu powinno być logo" &gt;
      {% endblock %}
     {% block page_content %}
        {% block page_title %}
              &lt;h1&gt;Szkoła podstawowa nr 1 im. Chucka Norrisa.&lt;/h1&gt;
        {% endblock %}
         {% block content_title %}
                  &lt;h2&gt;Klasy:&lt;/h2&gt;
         {% endblock %}
         {% block content %}
                  &lt;ul&gt;
                      {% for object in objects %}
                          {% block element %}
                              &lt;li&gt;&lt;a href='/{% block link %}class{% endblock %}/{}'&gt;{}&lt;/a&gt;&lt;/li&gt;
                          {% endblock %}
                      {% endfor %}
                  &lt;/ul&gt;
         {% endblock %}
         {% block additional %}
         {% endblock %}
     {% endblock %}
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>'''</p>
  
  <p>Problem is in this part of code, but I don't know why:</p>
  
  <pre><code>@property
  def name(self):
      return "Nazwa: {}, cena: {}".format(self.name, self.price)
  
  def __str__(self):
      return self.name
  </code></pre>
  
  <p>in this row (this is line 88 in models.py)</p>
  
  <p>return "Nazwa: {}, cena: {}".format(self.name, self.price)</p>
  
  <p>error messages:</p>
  
  <p>Request Method:     GET
  Request URL:    <a href="http://127.0.0.1:8000/categories/1234C" rel="nofollow noreferrer">http://127.0.0.1:8000/categories/1234C</a>
  Django Version:     3.0
  Exception Type:     RecursionError
  Exception Value:    </p>
  
  <p>maximum recursion depth exceeded while calling a Python object</p>
  
  <p>Exception Location:     /home/marekk/Pulpit/kurs/django-za2/WAR_PYT_W_11_Zaawansowane_Django/3_Django/coderslab/exercises/models.py in name, line 88</p>
  
  <p>to views.py I added:</p>
  
  <pre><code>from django import template
  register = template.Library()
  @register.filter
  def multiply(value, arg):
      return value * arg
  </code></pre>
  
  <p>to template I added:</p>
  
  <pre><code>{{ product.price|multiply:product.vat }}
  </code></pre>