N
N
NerVik2016-08-11 12:05:57
Django
NerVik, 2016-08-11 12:05:57

What is the best way to organize models?

Hello, there are some models like this:

LANG = (
    ('unknown', _('Unknown')),
    ('abk', _('Abkhazian')),
    ('ace', _('Achinese')),
    ('ach', _('Acoli')),
    ('eng', _('English')),
    ('rus', _('Russian'))
...
)

class Edition(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField(blank=True)
    lang  = models.IntegerField(choices=LANG)
    book = models.ForeignKey('Book')

class Book(models.Model):
    pass

in the database there is, let's say, 1 book and 10 publications referring to it, the languages ​​of the publications are eng, eng, rus. abk, ace, rus, eng, ace, unknown, eng.
task: When viewing a book, display a description in English and the user's language, let it be Russian.
problem: there can be several publications in the same language (in the example rus, eng, ace and the descriptions, even in the same language, differ slightly. another description.The
only decision that comes to my mind is to move the descrition into a separate model and make fk from the Edition.But it is not clear how correct this is.But in this case, I get rid of, in fact, duplicate information in the form of a lot of almost identical descriptions.
But maybe there is a better/easier/more convenient way?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sim3x, 2016-08-11
@NerVik

Depending on how the edition and its description are connected. It is
more logical that each edition has its own description.
Those do not make a separate model for descriptions.

A
Abdulla Mursalov, 2016-08-11
@amaprograma

Store language-description pairs in jsonfield or hstore, although you will have to work on the admin panel. It is easier and more convenient, indeed, to store in a separate model

D
Dmitry Tallmange, 2016-08-11
@p00h

The only decision that comes to my mind is to move descrition into a separate model and from Edition make fk on it

The only reasonable solution here in my opinion

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question