Skip to content
Permalink
Browse files
Extract common model enforcing id & created fields
  • Loading branch information
Gary Martin committed Jun 6, 2018
1 parent 3854c5d commit 367f2190b9ca1e79cb8bdb707b0a473446ce7250
Showing 1 changed file with 11 additions and 16 deletions.
@@ -24,14 +24,18 @@

logger = logging.getLogger(__name__)


class Ticket(models.Model):
class ModelCommon(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
created = models.DateTimeField(auto_now_add=True, editable=False)

class Meta:
abstract = True

class Ticket(ModelCommon):

def last_update(self):
last_event = self.changeevent_set.order_by('event_time').last()
return self.created if last_event is None else last_event.event_time
last_event = self.changeevent_set.order_by('created').last()
return self.created if last_event is None else last_event.created

def add_field_event(self, field, newvalue):
current_lines = self.get_field_value(field).splitlines(keepends=True)
@@ -48,25 +52,16 @@ def get_field_value(self, field):
except TicketField.DoesNotExist as e:
return ''

event = self.changeevent_set.filter(field=tfield).order_by('event_time').last()
event = self.changeevent_set.filter(field=tfield).order_by('created').last()
return '' if event is None else event.value()


class TicketField(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class TicketField(ModelCommon):
name = models.CharField(max_length=32)

class Label(TicketField):
pass

class SharedField(TicketField):
pass

class ChangeEvent(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class ChangeEvent(ModelCommon):
ticket = models.ForeignKey(Ticket, models.CASCADE, editable=False, null=False)
field = models.ForeignKey(TicketField, models.CASCADE, editable=False, null=False)
event_time = models.DateTimeField(auto_now_add=True, editable=False)
diff = models.TextField(editable=False)

def value(self, which=2):

0 comments on commit 367f219

Please sign in to comment.