Hi guys,
I have started looking into Django more closely, recently and thus started to create a vocabulary learning app.
Right now, the admin (me :-D) can add a Word via the admin-backend that consists of language, word translation, Words
Here I can also either create languages and words independently or via Word translations, as you can see in the code below.
Now, I have the result looking somewhat like this:
<QuerySet [<WordTranslation: 3 Morgen, Bahasa Indonesia: Pagi >]>
3: ID, Morgen (german word), Bahasa Indonesia (language to learn): Pagi (word meaning in said language).
This is my models.py:
class Language(models.Model):
name = models.CharField(max_length=20)
def __str__(self):
return self.name
class Word(models.Model):
word = models.CharField(max_length=50)
def __str__(self):
return self.word
class WordTranslation(models.Model):
vocabulary = models.ForeignKey(Word, on_delete=models.CASCADE)
language = models.ForeignKey(Language, on_delete=models.CASCADE)
translation = models.CharField(max_length=50)
def __str__(self):
return f' {self.pk} {self.vocabulary}, {self.language}: {self.translation} '
class Meta:
unique_together = ['vocabulary', 'language', 'translation']
I want to be able to switch between languages easily, but since I’d have to setup every word translation as an extra word for now, I am stuck with adding every word twice but with the translation and vocabulary changed…
i.e. adding a word in both languages and just switch vocabulary and translation around. This seems inefficient.
I want to avoid hardcoding languages, thus having translation_id, and translation_de is not really a solution.
Is there an easy way to modify the model to allow me to easily switch between languages:
<h1> What does <span style="color:red;">{{ vocabulary }}</span> mean in <span style="color:green;">{{ language }}?</span></h1>
(vocabulary outputs Morgen and language gives Bahasa Indonesia)
I fear this might get out of hand, as I don’t have much experience with modelling dbs, other than textual data (TEI) or simpler entries (calendar events, blog entries, etc.).
Any hints or would this be the best solution for that?
It should, ideally, be expandable to allow n languages, so that I can easily add “support for another language” (i.e. add a language in the admin-site and then populate the model accordingly)
For now I somehow have a json-file (or a dict) that looks somewhat like this in mind:
{pk:pk,
concept:english_version,
dt:german_version,
indo:indonesian_version
}
Now the annoying thing that I am thinking off:
How about an easy way to add support for more languages? If let’s say people want to learn Italian ad I decide to add a column italian. How do I get existing entries to automatically update to have
{pk:pk,
concept:english_version,
dt:german_version,
indo:indonesian_version
it: ""
}
so that I can add the meaning of the word in the admin backend, so that in the following screenshot there is no Language to, but just german_version, indo_version, ital_version and the admin has to enter all data accordingly.
(I know the last step is not essential for now)
I am not sure whether I actually need all my models, thinking about it now, I think I could get away with
WordPhrase and Language, but I am probably oversimplifying things here.
Can anyone help with that?