· 7 years ago · Jun 02, 2018, 09:42 AM
1class Settings(models.Model):
2 # basic settings
3 include_basic = models.BooleanField(default=True, null=False)
4 include_people = models.BooleanField(default=False, null=False)
5
6 class Meta:
7 abstract = True
8
9class Account(models.Model):
10 # the user that this account belongs to
11 user = models.ForeignKey(User, related_name='accounts')
12 # basic account info
13 username = models.CharField(max_length=100, null=False)
14
15 class Meta:
16 abstract = True
17
18 @classmethod
19 def get_all_for_user(cls, user):
20 accounts = list(user.accounts.all())
21 account_ids = []
22 for account in accounts:
23 account_ids.append(account.id)
24 helpers.cache_log(account_ids)
25 settings = models.Settings.objects.filter(account_id__in=account_ids)
26 return accounts
27
28class TwitterAccount(Account):
29 # auth info
30 oauth_token = models.CharField(max_length=75, null=True)
31 oauth_secret = models.CharField(max_length=75, null=True)
32
33 @property
34 def linked(self):
35 return bool(self.oauth_token and self.oauth_token)
36
37 def __unicode__(self):
38 return u'TwitterAccount: user=%s, username=%s' % (self.user, self.username)
39
40class TwitterSettings(Settings):
41 include_public_messages = models.BooleanField(default=True, null=False)
42 include_direct_messages = models.BooleanField(default=False, null=False)
43
44 def __unicode__(self):
45 return u'TwitterSettings'