models.py
class Project(models.Model):
"""Проект"""
title = models.CharField("Название", max_length=200)
description = models.TextField("Описание")
lesson = models.ForeignKey(Lesson, verbose_name="предметы", on_delete=models.SET_NULL, null=True)
student = models.ManyToManyField(Student, verbose_name="ученики(цы)", related_name="student_project")
create_date = models.DateField("Дата создания", default=now())
url = models.SlugField(max_length=160, unique=True)
done = models.BooleanField("Завершённый", default=False)
poster = models.ImageField("Постер", upload_to="student_projects/")
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("project_detail", kwargs={"slug": self.url})
class Meta:
verbose_name = "Проект"
verbose_name_plural = "Проекты"
class Lesson(models.Model):
"""Предмет"""
title = models.CharField("Название", max_length=150)
image = models.ImageField("Изображение", upload_to="lessons/")
url = models.SlugField(max_length=160, unique=True)
def __str__(self):
return self.title
class Meta:
verbose_name = "Предмет"
verbose_name_plural = "Предметы"
views.py
class LessonsView(ListView):
"""Список предметов"""
model = Lesson
queryset = Lesson.objects.all()
class ProjectsView(ListView):
"""Список проектов"""
model = Project
queryset = Project.objects.all() #lesson__title="Математика"
lesson_list.html
{% for lesson in lesson_list %}
<form>
<div class="col-md-4">
<a href=" ">
<div class="card mb-4 shadow-lg rounded">
<!--<div class="men-thumb-item">
<img src="{{ lesson.image.url }}" class="img-fluid" alt="" >
</div>-->
<div class="men-thumb-item" style="width: 500px; height: 250px; border-width: 2px ;border-color: #a30f1d">
<p style="text-decoration: none; color: #721c24">{{ lesson.title }}</p>
</div>
</div>
</a>
</div>
</form>
{% endfor %}