Skip to content

Commit

Permalink
Actually Add AccountWrapper Model...
Browse files Browse the repository at this point in the history
  • Loading branch information
prikhi committed Nov 13, 2015
1 parent e1a57fa commit 7aa3a8d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions acornaccounting/core/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""This module contains abstract models used throughout the application."""
from django.db import models

from accounts.models import Account


class AccountWrapper(models.Model):
"""An abstract wrapper for Account instances.
This model is used to provide a limited selection of manually curated
Accounts with Communard-friendly names, for Communard-facing forms - for
example, Local Store Accounts for Trips and Credit Card Accounts for Credit
Cards.
"""
account = models.ForeignKey(Account)
name = models.CharField(
max_length=50, blank=True,
help_text="A name for Communards. Defaults to the Account's Name",
)

class Meta(object):
abstract = True
ordering = ('name',)

def __unicode__(self):
return self.name

def save(self, *args, **kwargs):
"""Pull the name from the Account if blank."""
if not self.name and self.account:
self.name = self.account.name
super(AccountWrapper, self).save(*args, **kwargs)

0 comments on commit 7aa3a8d

Please sign in to comment.