O
O
organica2019-11-07 21:03:32
Django
organica, 2019-11-07 21:03:32

ValueError: invalid literal for int() with base 10: 'Pallet_Truck'. Where is the mistake?

Misters, help to understand an error. I understand its essence - an attempt to convert a string to a number. However, in the foreseeable code, no operations with numbers occur. Where is the "dog" buried?
URLS.PY

from django.urls import path
from . import views
from .views import tech_type_list

urlpatterns = [
    path('', views.tech_list, name='tech_list'),
    path('<tech_type>/', tech_type_list, name='tech_type'),
]

Models.py
from django.db import models


class TechType(models.Model):
    type_name = models.CharField(max_length=100, verbose_name='Вид техники', unique=True)

    def __str__(self):
        return self.type_name


class TechUnit(models.Model):
    inner_id = models.CharField(max_length=100, verbose_name='Внутренний номер', unique=True)
    tech_type = models.ForeignKey(TechType, on_delete=models.CASCADE, verbose_name='Вид техники')

    def __str__(self):
        return self.inner_id

Views.py
from django.shortcuts import render
from .models import TechType, TechUnit
from django.shortcuts import render, get_object_or_404


def tech_list(request):
    tech_type = TechType.objects.order_by('type_name')
    return render(request, 'checklist/tech_list_page.html', {'tech_type': tech_type})


def tech_type_list(request, tech_type):
    template = 'checklist/tech_detail.html'
    tech_list = TechUnit.objects.filter(tech_type=tech_type)
    context = {
        'tech_list': tech_list,
    }
    return render(request, template, context)

Well, actually the template in which I'm trying to display all this
{% extends 'checklist/base.html' %}

{% block content %}
<h1>Единицы техники типа {{ tech_list.tech_type }}</h1>
<ul>
    {% for item in tech_list %}
    <li>{{ item }}</li>
    {% endfor %}
</ul>
{% endblock %}

If you give an instance of the tech_type class a name consisting of numbers, there are no errors. If you enter letters, ValueError: invalid literal for int() with base 10 appears. Where is Django trying to convert letters to numbers?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question