Answer the question
In order to leave comments, you need to log in
How to Implement table selection in Django ORM table field?
I came across the following task:
Implement the main table with the fields title, date, description in which you can select another table with fields, but only one. In the main table, select a category with a set of fields.
class BaseTable(models.Model):
title = models.CharField(max_length=50)
date = models.DateTimeField(auto_now_add=True)
descriptions = models.TextField()
class A(models.Model):
bed = models.CharField(max_length=50)
height = models.CharField(max_length=50)
base_ads = models.OneToOneField('BaseTable', on_delete=models.CASCADE, related_name='a')
class B(models.Model):
mat = models.CharField(max_length=50)
quality = models.CharField(max_length=50)
size = models.CharField(max_length=50)
base_ads = models.OneToOneField('BaseTable', on_delete=models.CASCADE, related_name='b')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question