models.py 2.01 KB
from django.db import models


class ExpansionOpinion(models.Model):
    key = models.CharField(max_length=16, unique=True)
    priority = models.PositiveIntegerField()

    class Meta:
        ordering = ['priority']

    def __str__(self):
        return self.key

class PhraseExpansionType(models.Model):
    phrase_type = models.CharField(max_length=16)
    phrase_subtype = models.CharField(max_length=32, null=True)
    max_positions = models.PositiveIntegerField(default=1)
    
    class Meta:
        ordering = ['phrase_type', 'phrase_subtype']
    
    def __str__(self):
        return '{}({})'.format(self.phrase_type, self.phrase_subtype) if self.phrase_subtype else self.phrase_type

class PhraseExpansion(models.Model):
    expansion_type = models.ForeignKey(PhraseExpansionType, on_delete=models.PROTECT, related_name='expansions')
    opinion = models.ForeignKey(ExpansionOpinion, on_delete=models.PROTECT)
    priority = models.PositiveIntegerField()
    
    class Meta:
        ordering = ['priority']
    
    def __str__(self):
        return '{}: {}'.format(self.opinion, ' + '.join([str(pos) for pos in self.positions.all()]))

class ExpansionPosition(models.Model):
    expansion = models.ForeignKey(PhraseExpansion, on_delete=models.PROTECT, related_name='positions')
    priority = models.PositiveIntegerField()
    
    class Meta:
        ordering = ['priority']
    
    def __str__(self):
        return '{%s}' % (';'.join([str(pt) for pt in self.phrases.all()]))

class ExpansionPhrase(models.Model):
    position = models.ForeignKey(ExpansionPosition, on_delete=models.PROTECT, related_name='phrases')
    text_rep = models.TextField()
    
    class Meta:
        ordering = ['text_rep']
    
    def __str__(self):
        return self.text_rep

class ExpansionPhraseDescription(models.Model):
    phrase = models.ForeignKey(ExpansionPhrase, on_delete=models.PROTECT, related_name='descriptions')
    lang = models.CharField(max_length=2, choices=[('pl', 'pl'), ('en', 'en')])
    description = models.TextField(null=True)