Consider the example below:
class Vehicle(models.Model):
vehicle = models.CharField(_('veículo'), max_length=50, unique=True)
price = models.DecimalField(_(u'preço'), max_digits=8, decimal_places=2)
kit_fabric = models.ForeignKey(
"Kit", verbose_name=u'kit de fábrica', related_name='vehicle_kit')
class Accessory(models.Model):
accessory = models.CharField(_(u'accessório'), max_length=50)
price_accessory = models.DecimalField(
_(u'preço'), max_digits=8, decimal_places=2)
class Kit(models.Model):
kit = models.CharField(max_length=50)
class KitDetail(models.Model):
kit = models.ForeignKey("Kit", verbose_name='kit', related_name='kit_det')
accessory = models.ForeignKey(
"Accessory", verbose_name=u'accessório', related_name='accessory_kit')
quantity_accessory = models.PositiveIntegerField(_('quantidade'))
def __str__(self):
return str(self.kit)
class Ordered(TimeStampedModel):
customer = models.ForeignKey("Customer", verbose_name='cliente')
employee = models.ForeignKey("Employee", verbose_name=u'funcionário')
vehicle = models.ForeignKey("Vehicle", verbose_name=u'veículo')
kit_optional = models.ForeignKey("Kit", verbose_name='kit opcional')
dealership = models.ForeignKey(
"Dealership", verbose_name=u'concessionária')
kiosk = models.ForeignKey("Kiosk", verbose_name='quiosque')
status = models.CharField(max_length=2, choices=status_list, default='p')
How do I get the description of the accessories in the order?
That is, in my template I need:
{{ object.kit_optional.accessory }} e
{{ object.kit_optional.price_accessory }}
{{ object.kit_optional.quantity_accessory }}