models.py
2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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)