I am coding up a dictionary using Django.
I want a word to have multiple definitions, if necessary.
This would be a one-to-many relationship, but Django does not seem to have a OneToManyField
.
This is a snippet of my code:
class Definition(models.Model):
definition = models.CharField(max_length=64)
class Word(models.Model):
word = models.CharField(max_length=64, unique=True)
definitions = models.ForeignKey(Definition, on_delete=models.CASCADE, related_name="word")
I would like to do word.definitions
and get back all the definitions of that word.
Also, deleting a word should delete all definitions of that word. Finally, a_definition.word
should give me the word associated with that definition.