Reputation: 12187
So right now my model looks like this...
class Language()
name= Char()
class Word
id = pk()
language = ForeignKey(language)
name = Char()
class Translation()
original = FoeignKey(word)
L2 = ForiegnKey(language)
definition = Text()
translation = Char()
The problem I have with this is that say I have two languages (English/Spanish) and two words (el/la, the). With my current model I would have to have two translation objects for these two words.
class Language()
name= Char()
class Word
id = pk()
language = ForeignKey(language)
name = Char()
class Translation()
language1 = FoeignKey(word)
language2 = ForiegnKey(word)
definition_language1 = Text()
definition_language2 = Text()
Although I tried to do option 2 and I think it wouldn't let me directly have to ForeignKeys to the word class.
I think I have thought myself into a corner, and I can't decide if it is totally necessary to do option 2 or not. Is it even possible?
Upvotes: 0
Views: 41
Reputation: 4415
Isn't what you have more of the structure where you have a Word table, a Language table, and then your translation table is a through table connecting the Word table with itself. Then you can put all that additional information on the through table, and query it as a connection between two Word objects
If you don't know what a through table is, the documentation for how to use it can be found here: https://docs.djangoproject.com/en/1.8/topics/db/models/#extra-fields-on-many-to-many-relationships
Upvotes: 1
Reputation: 379
Why not use your second example with a related_name
?
class Translation()
language1 = ForeignKey(word, related_name = 'masculine')
language2 = ForeignKey(word, related_name = 'feminine')
Upvotes: 0