forked from henriklied/django-twitter-oauth
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodels.py
56 lines (45 loc) · 2.18 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
try:
#if using south, like i am, we need to map some rules
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^twitter_auth\.models\.PositiveBigIntegerField"])
except:
pass
# Based on http://www.numlock.ch/news/it/django-custom-model-field-for-an-unsigned-bigint-data-type/
class PositiveBigIntegerField(models.PositiveIntegerField):
"""Represents MySQL's unsigned BIGINT data type (works with MySQL only!)"""
empty_strings_allowed = False
def get_internal_type(self):
return "PositiveBigIntegerField"
def db_type(self, connection):
# This is how MySQL defines 64 bit unsigned integer data types
return "bigint UNSIGNED"
class MapTwitterToUser(models.Model):
twitter_id = PositiveBigIntegerField(null=False, blank=False)
user = models.ForeignKey(User)
def __unicode__(self):
return 'Twitter id: %s, User is: %s' % (self.twitter_id, self.user)
class Meta:
#ordering = ("-reverse_rank",)
app_label = "twitter_auth"
verbose_name = "maptwittertouser"
verbose_name_plural = "maptwittertousers"
class TwitterAuthUserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
access_token = models.CharField(max_length=255, blank=True, null=True, editable=False)
profile_image_url = models.URLField(blank=True, null=True)
location = models.CharField(max_length=100, blank=True, null=True)
url = models.URLField(blank=True, null=True)
description = models.CharField(max_length=160, blank=True, null=True)
last_update = models.DateTimeField(blank=False, auto_now=True)
def __str__(self):
return '%s\'s profile' % self.user
#Let's make this an abstract class
class Meta(object):
abstract = True
#def create_user_profile(sender, instance, created, **kwargs):
# if created:
# profile, created = TwitterAuthUserProfile.objects.get_or_create(user=instance)
#post_save.connect(create_user_profile, sender=User)