Skip to content

Instantly share code, notes, and snippets.

@ir4y
Created July 11, 2013 10:43
Show Gist options
  • Save ir4y/5974453 to your computer and use it in GitHub Desktop.
Save ir4y/5974453 to your computer and use it in GitHub Desktop.
class Transaction(models.Model):
owner = models.ForeignKey('auth.User')
datetime = models.DateTimeField(auto_now_add=True)
amount = models.PositiveIntegerField()
approved = models.BooleanField(default=False)
result = models.PositiveIntegerField(blank=True, null=True)
error = models.TextField(blank=True, null=True)
error_code = models.PositiveIntegerField(blank=True, null=True)
def operation_result(self):
if self.approved:
return self.result
else:
return "{0} {1}".format(self.error_code, self.error)
class Meta:
ordering = ("-datetime", )
class TransactionHistory(models.Model):
OPERATION_CHOICES = (
(BUY, u'Покупка'),
(CASH_PAYMENT_IN, u'Начисление на счет'),
(CASH_PAYMENT_OUT, u'Вывод со счета'),
)
datetime = models.DateTimeField(verbose_name=u'Дата операции', auto_now=True)
user = models.ForeignKey('auth.User', verbose_name=u'Пользователь')
operation_amount = models.FloatField(verbose_name=u'Сумма операции')
start_user_amount = models.FloatField(verbose_name=u'Сумма пользователя на начало опрации')
finish_user_amount = models.FloatField(verbose_name=u'Сумма пользователя на конец опрации')
operation = models.IntegerField(verbose_name=u'Операция',
choices=OPERATION_CHOICES)
content_type = models.ForeignKey(ContentType, blank=True, null=True)
object_id = models.PositiveIntegerField(blank=True, null=True)
operation_object = generic.GenericForeignKey('content_type', 'object_id')
def __unicode__(self):
return '%s %s' % (self.profile.__unicode__(), self.get_operation_display())
class Meta:
verbose_name = u'Дейcтвие'
verbose_name_plural = u'История действий'
ordering = ['-datetime']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment