Answer the question
In order to leave comments, you need to log in
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'),
]
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
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)
{% extends 'checklist/base.html' %}
{% block content %}
<h1>Единицы техники типа {{ tech_list.tech_type }}</h1>
<ul>
{% for item in tech_list %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% endblock %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question