Created
February 13, 2014 12:01
-
-
Save csarcom/8973900 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Account(PolymorphicMPTTModel): | |
parent = PolymorphicTreeForeignKey('self', | |
null=True, | |
blank=True, | |
related_name='children', | |
verbose_name=_('parent')) | |
name = models.CharField(max_length=150, unique=True) | |
company_name = models.CharField(max_length=150, unique=True, | |
help_text=_('Corportate Name')) | |
is_active = models.BooleanField( | |
_('Active'), default=True, | |
help_text="If your account is deactivaded, you can't log in again.") | |
unique_identifier = models.CharField( | |
max_length=20, | |
help_text='Company document number. e.g. SSN') | |
def save(self, *args, **kwargs): | |
if not self.is_active: | |
# cascade updating to deactivate children accounts | |
self.get_descendants(True).update(is_active=False) | |
super(Account, self).save(*args, **kwargs) | |
class AccountInfo(models.Model): | |
address = models.CharField(max_length=150) | |
complement = models.CharField(max_length=150, null=True, blank=True) | |
city = models.CharField(max_length=45) | |
state = models.CharField(max_length=45) | |
postal_code = models.CharField(max_length=15) | |
country = models.ForeignKey(Country) | |
class Meta: | |
abstract = True | |
class Brand(Account): | |
pass | |
class Company(Account, AccountInfo): | |
currency = models.ForeignKey(Currency, null=True, blank=True) | |
class Reseller(Account, AccountInfo): | |
pass | |
class Client(Account, AccountInfo): | |
client_id = models.CharField(max_length=5, null=False, blank=False, | |
unique=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment