-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
71 lines (55 loc) · 2.75 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from django.contrib.auth.models import User
from django.contrib.postgres.fields import JSONField
from django.db import models
from leather.accounts.utils import slugify_uniquely
class PlaidAccount(models.Model):
access_token = models.CharField(max_length=200)
public_token = models.CharField(max_length=200, blank=True, null=True)
user = models.ForeignKey(User, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return 'Plaid Account for {} ({})'.format(self.user,
self.access_token[-4:])
class Account(models.Model):
custom_name = models.CharField(max_length=255, blank=True, null=True)
name = models.CharField(max_length=255)
plaid_account = models.ForeignKey(PlaidAccount, blank=True, null=True)
plaid_id = models.CharField(max_length=50, blank=True, null=True)
slug = models.SlugField(max_length=255, blank=True)
typ = models.CharField(max_length=50, blank=True, null=True)
user = models.ForeignKey(User, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.name
def save(self, *args, **kwargs):
self.slug = slugify_uniquely(self.custom_name or self.name,
Account,
self.user)
return super(Account, self).save(*args, **kwargs)
class Transaction(models.Model):
account = models.ForeignKey(Account, related_name='transactions')
amount = models.DecimalField(max_digits=10, decimal_places=2)
custom_name = models.CharField(max_length=255, blank=True, null=True)
date = models.DateField()
memo = models.CharField(max_length=255, blank=True, null=True)
name = models.CharField(max_length=255)
pending = models.BooleanField(default=False)
pending_transaction = models.ForeignKey("Transaction",
blank=True,
null=True)
plaid_categories = JSONField(blank=True, null=True)
plaid_category_id = models.CharField(max_length=50, blank=True, null=True)
plaid_id = models.CharField(max_length=50, blank=True, null=True)
plaid_meta = JSONField(blank=True, null=True)
plaid_score = JSONField(blank=True, null=True)
typ = JSONField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.name
def get_absolute_url(self):
return '/transactions/{}/'.format(self.id)
class Meta:
ordering = ['-date', '-created_at']