-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actually Add AccountWrapper Model...
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |