Skip to content

Instantly share code, notes, and snippets.

@sankalpjonn
Last active July 18, 2021 02:11
Show Gist options
  • Save sankalpjonn/7b1390add5e3c2e28721862233a87421 to your computer and use it in GitHub Desktop.
Save sankalpjonn/7b1390add5e3c2e28721862233a87421 to your computer and use it in GitHub Desktop.
from django.db import models
from django.contrib.auth.models import User
from django.db import models, transaction
class Account(models.Model):
balance = models.IntegerField(default=0)
user = models.ForeignKey(User)
def deposit(self, amount):
self.balance += amount
self.save()
def withdraw(self, amount):
if amount > self.balance:
raise errors.InsufficientFunds()
self.balance -= amount
self.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment