Я получаю ошибку, когда пытаюсь использовать объекты price и discount_price из класса Equipment в классе EquipmentOrderItem
, вот класс в моем файле models.py
class EquipmentOrderItem(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL,
on_delete=models.CASCADE)
ordered = models.BooleanField(default=False)
equipment = models.ForeignKey(Equipment, on_delete=models.CASCADE)
quantity = models.IntegerField(default=1)
objects = models.Manager()
def __str__(self):
return f"{self.quantity} of {self.equipment.name}"
def get_total_equipment_price(self):
return self.quantity * self.equipment.price
def get_total_discount_equipment_price(self):
return self.quantity * self.equipment.discount_price
вот класс, из которого я хочу получить объект
class Equipment(models.Model):
name = models.CharField(max_length=200)
pic = models.ImageField(upload_to='gallery')
description = models.TextField(default='about item')
price = models.FloatField(default=0)
discount_price = models.FloatField(blank=True, null=True)
category = models.CharField(choices=CATEGORY_CHOICES, max_length=3, default='VID')
label = models.CharField(choices=LABEL_CHOICES, max_length=1, default='P')
slug = models.SlugField()
objects = models.Manager()
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('create:equipment_detail', kwargs={
'slug': self.slug
})
def get_add_to_cart_url(self):
return reverse("create:add_to_cart", kwargs={
'slug': self.slug
})
def get_remove_from_cart_url(self):
return reverse("create:remove_from_cart", kwargs={
'slug': self.slug
})
, здесь я делаю вызов из шаблона
{% for equipment_order_item in object.equipments.all %}
<tr>
<th scope="row">1</th>
<td>{{ equipment_order_item.equipment.name }}</td>
<td>{{ equipment_order_item.equipment.price }}</td>
<td>{{ equipment_order_item.quantity }}</td>
<td>
{% if equipment_order_item.discount_price %}
#{{ equipment_order_item.quantity.get_total_discount_equipment_price }}
(Saving #{{ equipment_order_item.get_amount_saved }})
{% else %}
#{{ equipment_order_item.quantity.get_total_equipment_price }}
{% endif %}
</td>
</tr>
{% endfor %}