同义词和反义词在当地语言的django词典应用程序中

时间:2018-04-22 20:01:14

标签: django dictionary

对不起这个问题,但我在制作本地语言的词典应用程序时遇到问题,所以我不需要英语词典,我的问题是同义词,我无法弄清楚如何在我的模型中实现它

from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse


# Create your models here.
class Voca(models.Model):
    name = models.CharField(max_length=200, unique=True)

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse("voca:detail", kwargs={"id": self.id, "name": self.name})

class Defination(models.Model):
    voca = models.ForeignKey(Voca, related_name='definations')
    defination = models.CharField(max_length=500)
    example = models.CharField(max_length=500)
    etymology = models.CharField(max_length=500)
    author = models.ForeignKey(User, default=1)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ('created',)

    def __str__(self):
        return 'Defination given by {} on {}'.format(self.author, self.voca)

class Synonym(models.Model):
    words = models.ManyToManyField(Voca, blank=True, related_name='synonyms')

我希望用户将自己的单词,同义词,反义词定义添加到数据库本身,因为它是一种俚语,所以如果我能得到任何帮助,尤其是反义词和同义词,我真的很感激...谢谢

1 个答案:

答案 0 :(得分:0)

我的建议是删除Synonym模型并向Defination模型添加字段。

class Defination(models.Model):
    voca = models.ForeignKey(Voca, related_name='definations')
    ...
    synonyms = models.ManyToManyField(Voca, related_name='synonyms')
    antonyms = models.ManyToManyField(Voca, related_name='antonyms')