2
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 on request?
I mean, in my template I need to:
{{ object.kit_optional.accessory }} e
{{ object.kit_optional.price_accessory }}
{{ object.kit_optional.quantity_accessory }}
What would that be
object
? You’re a little confused, there’s aclass Kit
and theclass KitDetail
, it would not be better to unite these two?– Paulo
@Orion O
KitDetail
exists because each kit can various accessories. You think it would be better to use a M2m betweenKit
andAccessory
?– Regis Santos
It would be better if.
– Paulo