Created
July 28, 2010 16:33
-
-
Save mikebannister/495159 to your computer and use it in GitHub Desktop.
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
class Settings(models.Model): | |
# basic settings | |
include_basic = models.BooleanField(default=True, null=False) | |
include_people = models.BooleanField(default=False, null=False) | |
class Meta: | |
abstract = True | |
class Account(models.Model): | |
# the user that this account belongs to | |
user = models.ForeignKey(User, related_name='accounts') | |
# basic account info | |
username = models.CharField(max_length=100, null=False) | |
class Meta: | |
abstract = True | |
@classmethod | |
def get_all_for_user(cls, user): | |
accounts = list(user.accounts.all()) | |
account_ids = [] | |
for account in accounts: | |
account_ids.append(account.id) | |
helpers.cache_log(account_ids) | |
settings = models.Settings.objects.filter(account_id__in=account_ids) | |
return accounts | |
class TwitterAccount(Account): | |
# auth info | |
oauth_token = models.CharField(max_length=75, null=True) | |
oauth_secret = models.CharField(max_length=75, null=True) | |
@property | |
def linked(self): | |
return bool(self.oauth_token and self.oauth_token) | |
def __unicode__(self): | |
return u'TwitterAccount: user=%s, username=%s' % (self.user, self.username) | |
class TwitterSettings(Settings): | |
include_public_messages = models.BooleanField(default=True, null=False) | |
include_direct_messages = models.BooleanField(default=False, null=False) | |
def __unicode__(self): | |
return u'TwitterSettings' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment