Answer the question
In order to leave comments, you need to log in
How to merge duplicates in Django?
models
class Characteristics(models.Model):
name = models.CharField('Наименование', max_length=50)
slug = models.SlugField(max_length=160, unique=True)
class ProductCharacteristics(models.Model):
product = models.ForeignKey(
Product, verbose_name='Товар', on_delete=models.CASCADE)
characteristic = models.ForeignKey(
Characteristics, verbose_name='Характеристика', on_delete=models.CASCADE)
value = models.CharField('Значение', max_length=50)
def get_characteristics(self):
return ProductCharacteristics.objects.all()
{% for characteristic in view.get_characteristics %}
<div class="border-bottom pb-4 mb-4">
<h4>{{ characteristic.characteristic.name }}</h4>
<!-- Checkboxes -->
<div
class="form-group d-flex align-items-center justify-content-between font-size-1 text-lh-lg text-body mb-1">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="genderMen">
<label class="custom-control-label text-lh-lg" for="genderMen">{{ characteristic.value }}</label>
</div>
<small>73</small>
</div>
<!-- End Checkboxes -->
</div>
{% endfor %}
Answer the question
In order to leave comments, you need to log in
The name field is not unique. There can be any number of instances. Merge them - that's still crap, it's easier to immediately score there unique=True
class Characteristics(models.Model):
name = models.CharField('Наименование', max_length=50, unique=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question