""" Transaction Modles """ from django.core.exceptions import ValidationError from django.db import models from django.utils.translation import ugettext_lazy as _ from django.contrib.auth import get_user_model User = get_user_model() def validate_type(value): """Validate type value""" if value not in ('inflow', 'outflow'): raise ValidationError( _('%(value)s is not an even number'), params={'value': value}, ) class Transaction(models.Model): """ Transaction core model """ user = models.ForeignKey(User,related_name='transactions', on_delete=models.CASCADE) reference = models.CharField(_('Transaction reference'), max_length=8, unique=True, help_text=_('Unique value')) account = models.CharField(_('Account'), max_length=8, help_text=_('Account Number')) type = models.CharField(_('Type'), max_length=8, choices=(('inflow', 'inflow'), ('outflow', 'outflow')), validators=[validate_type], help_text=_('Choice "outflow" or "inflow"')) amount = models.FloatField(_('Amount'), max_length=255, help_text=_('''Only negative numbers for "outflow" and positive numbers for "inflow"''')) category = models.CharField(_('Category'), max_length=255, help_text=_('Category Name')) date = models.DateField('Date',help_text=_('Transaction date. YYYY-MM-DD format.'))