class yarn(models.Model):
title = models.CharField('Название', max_length=150)
description = models.TextField("Описание")
price = models.PositiveSmallIntegerField("Цена", default=0)
numberInStock = models.PositiveSmallIntegerField("Количество в наличии", default=0)
color = models.ManyToManyField(Color, verbose_name="Цвет")
creator = models.CharField("Производитель", max_length=150)
img = models.ImageField("Изображение", upload_to="img/")
url = models.SlugField(max_length=150, unique=True)
matirial = models.ManyToManyField(Matirial, verbose_name="Материал")
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('yarnDetail', kwargs={"slug": self.url})
class yarnView(ListView):
model = yarn
queryset = yarn.objects.all()
template_name = "yarn/katalog.html"
class yarnDetail(DetailView):
model = yarn
slug_field = "url"
{% for Yarn in Yarn__list %}
<div class="col-md-4 col-sm-12">
<div class="buy">
<img type="button" data-toggle="modal" data-target="#exampleModal{{Yarn.title}}" src="{{Yarn.img.url}}" alt="">
<a href="{{ Yarn.get_absolute_url}}" style="color: #212529">
<h3 class="float-left">{{Yarn.title}}</h3>
</a>
<div class="buy__text">
<div class="intocard">
<img src="https://img.icons8.com/material-two-tone/32/000000/shopping-basket-add.png" />
</div>
<div class="clearfix">
</div>
<a href="{{ Yarn.get_absolute_url}}" style="color: #212529">
<div class="prais">
<h4>цена: {{Yarn.price}}$/г</h4>
<h4>в наличии: {{Yarn.numberInStock}}г </h4>
</div>
</a>
</div>
</div>
<div>
<div class="modal fade" id="exampleModal{{Yarn.title}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<button type="button" class="close " data-dismiss="modal" aria-label="Close">
<span aria-hidden="true"><img src="https://img.icons8.com/small/40/000000/filled-cancel.png" /></span>
</button>
<div class="modal-body">
<img src="{{Yarn.img.url}}" class="modal__img" alt="">
</div>
</div>
</div>
</div>
</div>
{% endfor %}
<ul class="list">
<li> <strong>Производитель: </strong> {{yarn.creator}}</li>
<li> <strong>Материал: </strong> {% for matirial in yarn.matirial.all%} {{matirial}}
{% endfor %} </li>
<li> <strong>Цвет: </strong> {% for color in yarn.color.all %} {{color}}
{% endfor %}</li>
<li> <strong>Цена: </strong> {{yarn.price}}</li>
<li> <strong>Описание: </strong> {{yarn.description}}</li>
<li><button type="button" class="buy"> buy</button></li>
</ul>