models.py 1.15 KB
from django.db import models


class LexicalUnit(models.Model):
    entry = models.ForeignKey('connections.Entry', related_name='lexical_units', on_delete=models.PROTECT, null=True)
    luid = models.IntegerField(null=True)
    base = models.CharField(max_length=150)
    sense = models.CharField(max_length=5)
    #pos = models.ForeignKey('connections.POS', related_name='lexical_units', on_delete=models.PROTECT)
    pos = models.CharField(max_length=20)
    synset = models.ForeignKey('Synset', related_name='lexical_units', on_delete=models.PROTECT)
    definition = models.TextField(default='')
    gloss = models.TextField(default='')
    text_rep = models.TextField()

    class Meta:
        unique_together = ('base', 'sense', 'pos',)

    def __str__(self):
        return '%s-%s' % (self.base, self.sense)


class Synset(models.Model):
    id = models.IntegerField(primary_key=True)

    def __str__(self):
        text_rep = ''
        units_in_synset = LexicalUnit.objects.filter(synset__id=self.id)
        if units_in_synset.exists():
            first_lex_unit = units_in_synset.order_by('luid')[0]
            text_rep = str(first_lex_unit)
        return text_rep