unsupported operand type(s) for +: 'NoneType' and 'str'

Environment:


Request Method: GET
Request URL: http://localhost:8000/admin/stockmgmgt/stock/

Django Version: 5.0.6
Python Version: 3.12.3
Installed Applications:
['stockmgmgt',
 'crispy_forms',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\templates\admin\change_list.html, error at line 68
   unsupported operand type(s) for +: 'NoneType' and 'str'
   58 :         {% block search %}{% search_form cl %}{% endblock %}
   59 :         {% block date_hierarchy %}{% if cl.date_hierarchy %}{% date_hierarchy cl %}{% endif %}{% endblock %}
   60 : 
   61 :         <form id="changelist-form" method="post"{% if cl.formset and cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %} novalidate>{% csrf_token %}
   62 :         {% if cl.formset %}
   63 :           <div>{{ cl.formset.management_form }}</div>
   64 :         {% endif %}
   65 : 
   66 :         {% block result_list %}
   67 :           {% if action_form and actions_on_top and cl.show_admin_actions %}{% admin_actions %}{% endif %}
   68 :            {% result_list cl %} 
   69 :           {% if action_form and actions_on_bottom and cl.show_admin_actions %}{% admin_actions %}{% endif %}
   70 :         {% endblock %}
   71 :         {% block pagination %}{% pagination cl %}{% endblock %}
   72 :         </form>
   73 :       </div>
   74 :       {% block filters %}
   75 :         {% if cl.has_filters %}
   76 :           <div id="changelist-filter">
   77 :             <h2>{% translate 'Filter' %}</h2>
   78 :             {% if cl.is_facets_optional or cl.has_active_filters %}<div id="changelist-filter-extra-actions">


Traceback (most recent call last):
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\models\options.py", line 681, in get_field
    return self.fields_map[field_name]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^

During handling of the above exception ('action_checkbox'), another exception occurred:
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\utils.py", line 289, in lookup_field
    f = _get_non_gfk_field(opts, name)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\utils.py", line 322, in _get_non_gfk_field
    field = opts.get_field(name)
            ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\models\options.py", line 683, in get_field
    raise FieldDoesNotExist(
    ^

During handling of the above exception (Stock has no field named 'action_checkbox'), another exception occurred:
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\handlers\base.py", line 220, in _get_response
    response = response.render()
               ^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\response.py", line 114, in render
    self.content = self.rendered_content
                   ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\response.py", line 92, in rendered_content
    return template.render(context, self._request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\backends\django.py", line 61, in render
    return self.template.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 171, in render
    return self._render(context)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 163, in _render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\loader_tags.py", line 159, in render
    return compiled_parent._render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 163, in _render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\loader_tags.py", line 159, in render
    return compiled_parent._render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 163, in _render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\loader_tags.py", line 65, in render
    result = block.nodelist.render(context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\loader_tags.py", line 65, in render
    result = block.nodelist.render(context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\templatetags\base.py", line 45, in render
    return super().render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\library.py", line 258, in render
    _dict = self.func(*resolved_args, **resolved_kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\templatetags\admin_list.py", line 345, in result_list
    "results": list(results(cl)),
               ^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\templatetags\admin_list.py", line 321, in results
    yield ResultList(None, items_for_result(cl, res, None))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\templatetags\admin_list.py", line 312, in __init__
    super().__init__(*items)
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\templatetags\admin_list.py", line 217, in items_for_result
    f, attr, value = lookup_field(field_name, result, cl.model_admin)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\utils.py", line 298, in lookup_field
    value = attr(obj)
            ^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\options.py", line 999, in action_checkbox
    "aria-label": format_html(_("Select this object for an action - {}"), obj),
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\html.py", line 135, in format_html
    return mark_safe(format_string.format(*args_safe, **kwargs_safe))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\html.py", line 117, in conditional_escape
    return escape(text)
           ^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\functional.py", line 231, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\varte\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\html.py", line 50, in escape
    return SafeString(html.escape(str(text)))
                                  ^^^^^^^^^
  File "C:\Users\varte\OneDrive\Desktop\Projects\Stock Mangement\venv\src\stockmgmgt\models.py", line 25, in __str__
    return self.item_name+' '+str(self.quantity)
           ^^^^^^^^^^^^^^^^^^

Exception Type: TypeError at /admin/stockmgmgt/stock/
Exception Value: unsupported operand type(s) for +: 'NoneType' and 'str'

Side note: When posting code (or templates, error messages, tracebacks, etc), enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted. (I’ve taken the liberty of editing your original post. Please remember to do this in the future.)

This is saying that self.item_name is null for the model being rendered.

So, How do you resolve this error please?

To even begin to try to offer a suggestion, we’d need to see the model.

Thanks for you always relying to my post. I have resolve this error. I used this code def str(self):
return f"{self.item_name} {self.quantity}"