+
+class BaseTicket(models.Model):
+ ticket = models.CharField(_('ticket'), max_length=32)
+ created = models.DateTimeField(_('created'), auto_now=True)
+
+ class Meta:
+ abstract = True
+
+ def __init__(self, *args, **kwargs):
+ if 'ticket' not in kwargs:
+ kwargs['ticket'] = self._generate_ticket()
+ super(BaseTicket, self).__init__(*args, **kwargs)
+
+ def __unicode__(self):
+ return self.ticket
+
+ def _generate_ticket(self, length=29, chars=string.ascii_letters + string.digits):
+ """ Generates a random string of the requested length. Used for creation of tickets. """
+ return u"%s-%s" % (self.prefix, ''.join(Random().sample(chars, length)))
+
+
+class ServiceTicket(BaseTicket):