-
Notifications
You must be signed in to change notification settings - Fork 39
/
message.py
37 lines (27 loc) · 1.1 KB
/
message.py
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
# -*- coding: utf-8 -*-
#
from django.db import models
from django.utils.translation import ugettext_lazy as _
from result import Result
class MessageType(models.Model):
title = models.CharField(_('Title'), max_length=255, null=False, blank=False)
class Meta:
verbose_name = _('Message type')
verbose_name_plural = _('Message types')
def __unicode__(self):
return unicode(self.title)
class Message(models.Model):
text = models.TextField(_('Message'), max_length=1024, null=False, blank=False)
type = models.ForeignKey(MessageType)
def interpret(self, ctx):
ResultMessage.objects.create(result=ctx.result, message=self)
class Meta:
verbose_name = _('Message')
verbose_name_plural = _('Messages')
class ResultMessage(models.Model):
message = models.ForeignKey(Message, null=False, blank=False)
result = models.ForeignKey(Result, related_name='messages',
null=False, blank=False)
class Meta:
verbose_name = _('Result message')
verbose_name_plural = _('Result messages')