<filename>django_backend/wallet/models/transaction.py<gh_stars>1-10
import uuid
from django.db import models
from django.contrib.auth import get_user_model

from .currency import Currency
from .wallet import Wallet

user_model=get_user_model()

class Transaction(models.Model):
    id=models.UUIDField(
        primary_key=True,
        default=uuid.uuid4,
        editable=False)
    origin=models.ForeignKey(Wallet, on_delete=models.CASCADE, related_name='walletOrigin')
    destination=models.ForeignKey(Wallet, on_delete=models.CASCADE, related_name='walletDestination')
    value=models.DecimalField("Amount", max_digits=11, decimal_places=2)
    reason=models.CharField("Reason", max_length=50)
    reference_number=models.IntegerField("Reference number:")
    created_at=models.DateTimeField("Transaction created at",auto_now_add=True)
    successful=models.BooleanField("Wallet is successful?", default=True)
    active=models.BooleanField("Wallet is Active", default=True)
    
    def get_wallet_origin_balance(self):
        return self.origin.value 
    
    
    def __str__(self):
        return str(self.origin.name)+" - to - "+str(self.destination.name)



