path('state/', views.StateListView.as_view(), name = 'state'),
class StateListView(generic.ListView): model = state
<li><a href="{% url 'state' %}">Date</a></li>
@sim3x, <code>class state(models.Model):
date = models.DateField(help_text = 'Дата')
status = models.CharField(max_length=10, choices = (
('+', '+'),
('-', '-')
))
people = models.ForeignKey(people, help_text = 'Фамилия, имя учащегося', on_delete = models.SET_NULL, null=True)</code>
в нижнем регистре state
{% extends "base_generic.html" %}
{% block content %}
<h1>State List</h1>
{% if object_list %}
<table>
<tr>
<td>
People/day
</td>
{% for list in object_list%}
<td>{{ list.date}}</td>
{% endfor %}
</tr>
{% for i in object_list %}
<tr>
<td>
{{ i.people }}
</td>
{% for status in i %}
<td>
{% if status.status %}{{ status.status }}{% else %}?{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
{% else %}
<p>Данных нет!</p>
{% endif %}
{% endblock %}
Internal Server Error: /catalog/state/
Traceback (most recent call last):
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 158, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 156, in _get_response
response = response.render()
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\response.py", line 106, in render
self.content = self.rendered_content
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\response.py", line 83, in rendered_content
content = template.render(context, self._request)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 175, in render
return self._render(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 167, in _render
return self.nodelist.render(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 943, in render
bit = node.render_annotated(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\loader_tags.py", line 155, in render
return compiled_parent._render(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 167, in _render
return self.nodelist.render(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 943, in render
bit = node.render_annotated(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\loader_tags.py", line 67, in render
result = block.nodelist.render(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 943, in render
bit = node.render_annotated(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\defaulttags.py", line 314, in render
return nodelist.render(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 943, in render
bit = node.render_annotated(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\defaulttags.py", line 211, in render
nodelist.append(node.render_annotated(context))
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\Человек\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\defaulttags.py", line 167, in render
values = list(values)
TypeError: 'state' object is not iterable
Template error:
In template C:\Django\kids\catalog\templates\base_generic.html, error at line 9
'state' object is not iterable
1 : <!DOCTYPE html>
2 : <html lang="en">
3 : <head>
4 :
5 : {% block title %}<title>Local Library</title>{% endblock %}
6 : <meta charset="utf-8">
7 : <meta name="viewport" content="width=device-width, initial-scale=1">
8 : <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
9 : <script src="https://ajax.googleapis.com/ajax/libs/j query/1.12.4/jquery.m in.js"></script>
10 : <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
11 :
12 : <!-- Добавление дополнительного статического CSS файла -->
13 : {% load static %}
14 : <link rel="stylesheet" href="{% static 'css/styles.css' %}">
15 : </head>
16 :
17 : <body>
18 :
19 : <div class="container-fluid">
from django.shortcuts import render
from .models import people, state, school_class
from django.views import generic
def index(request):
num_state = state.objects.all().count()
num_people = people.objects.all().count()
return render(
request,
'index.html',
context = {'num_date':num_state, 'num_people':num_people})
class StateListView(generic.ListView):
model = state
from django.db import models
from django.urls import reverse
from datetime import date
from django.contrib.auth.models import User
import uuid
class school_class(models.Model):
school_class = models.CharField(max_length=10, help_text = 'Класс')
def __str__(self):
return self.school_class
class people(models.Model):
first_name = models.CharField(max_length=100, help_text = 'Имя учащегося')
last_name = models.CharField(max_length=100, help_text = 'Фамилия учащегося')
school_class = models.ManyToManyField(school_class, help_text = 'Класс ученика')
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
class date(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
date = models.DateField(help_text = 'Дата')
status = models.CharField(max_length=10, choices = (
('+', '+'),
('-', '-')
))
people = models.ForeignKey(people, help_text = 'Фамилия, имя учащегося', on_delete = models.SET_NULL, null=True)
def __str__(self):
return '{} {}'.format(self.date, self.people.__str__())
def get_absolute_url(self):
return reverse('date-detail', args=[str(self.id)])
class Meta:
ordering = ['date', 'people']
Не выводится только status(должен быть под днями), есть идеи, как сделать?