Добавление значений в ячейку таблицы в зависимости от модели

У меня есть в models.py

class Product(models.Model):
    class Meta:
        
      abstract = True
   
    name = models.CharField(max_length=250) 
    cost = models.IntegerField()

 class CPU(Product):
    
    SOCKETS = (
        ( 'AMD', (
        ('AM3', 'Socket AM3'),
        ('AM3+', 'Socket AM3'),
        ('AM4', 'Socket AM4'),
        ('TR4', 'Socket TR4'),
        )),

        ('Intel', (
        ('1336', 'Socket 1336'),
        ('1156', 'Socket 1156'),
        ('1155', 'Socket 1155'),
        ('2011', 'Socket 2011'),
        ('1356', 'Socket 1356'),
        ('1150', 'Socket 1150'),
        ('2011-3','Socket 2011-3'),
        ('1151', 'Socket 1151'),
        ('1151v2', 'Socket 1151v2'),
        ('2066', 'Socket 2066'),
        ('1200', 'Socket 1200'),
        ))
)
    sockets = models.CharField(max_length = 6, choices = SOCKETS, blank = True)

    def __str__(self):
        return self.name



class Motheboard(Product):
 
    FACTOR = (
        ('MicATX','Micro-ATX'),
        ('MinATX','Mini-ATX'),
        ('FATX','FlexATX'),
        ('ATX','ATX'),
        ('minITX','mini-ITX'),
        ('minDTX','mini-DTX'),
        ('eATX', 'Extended ATX'),

        )
    company = models.CharField(max_length = 80)
    form_factor = models.CharField(max_length = 6, choices = FACTOR, blank = True)
    
    def __str__(self):
        return self.name   

и в table.py

    class Meta:
        model = Product
        fields = ("name", "cost")

Я хочу добиться примерно следующего: | Имя | Стоимость | |------|------| | Ryzen 5 Socket AM4|30| | ASROCK B460M Micro-ATX |25|

How can I make the fields of child models appear in the cells with the name? Is it possible to do this in django tables or do you need to create your own fields in the database?
Thanks!

Сначала я переопределил метод рендеринга TemplateColumn.
Код в tables.py

cpus=[]
for i in CPU.objects.all():
    cpus.append(i.name)
motheboards=[]
for i in Motheboard.objects.all():
    motheboards.append(i.name)

class CustomTemplateColumn(tables.TemplateColumn):
    
    def render(self, record, table, value, bound_column, **kwargs):
        if record.name in cpus:
            return format_html("{} <br> {}", record.name, record.get_sockets_display())
        if record.name in motheboards:
            return format_html("{} <br> {} <br> {} ", record.name, record.company ,record.get_form_factor_display())
            
        return super(CustomTemplateColumn, self).render(record, table, value, bound_column, **kwargs)

class ProductTable(tables.Table):
    Name=CustomTemplateColumn('{{record.name}}')
    class Meta:
        model = Product
        fields = ("Name","cost")
Вернуться на верх