V
V
Vlad Rodionov2021-12-20 04:13:48
Django
Vlad Rodionov, 2021-12-20 04:13:48

How to store data in the database and which connection to choose?

There are three tables. How correct is the approach of such nested ManyToMany? Does it affect the database load? Quote.text is a unique value (quote) for each book. How to organize Quote.translate to store data in this form:
drive drive drive drive drive drive lead

class Translate(models.Model):
    text = models.TextField(blank=True, null=True)
    
class Quote(models.Model):
    text = models.TextField(blank=True, null=True)
    translate = models.ManyToManyField(Translate, blank=True)
        
class Book(models.Model):
    name = models.TextField(unique=True)
    quote = models.ManyToManyField(Quote, blank=True)


or would that be better?
class Book(models.Model):
    name = models.TextField(unique=True)

class Quote(models.Model):
    book= models.ForeignKey(Book, on_delete=CASCADE) 
    
class Translate(models.Model):
    quote= models.ForeignKey(Quote, on_delete=CASCADE)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-12-20
@RedFosfor

Obviously, one quote cannot be from different books, just as one translation cannot be different phrases, so the ratio must definitely be one to many.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question