models.py 1.18 KB
Newer Older
Jason D Yeomans's avatar
Jason D Yeomans committed
1
from django.db import models
2 3 4
from housing.models import User, Room, Class
from autoslug import AutoSlugField
from model_utils.models import TimeStampedModel
Jason D Yeomans's avatar
Jason D Yeomans committed
5 6
from allauth.socialaccount.models import SocialAccount
import hashlib
Jason D Yeomans's avatar
Jason D Yeomans committed
7 8

# Create your models here.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
class Major(TimeStampedModel):
    major_name = models.CharField(max_length = 30)

class Student(TimeStampedModel):
    user = models.OneToOneField(User)
    # Django user includes a username, password, email, first name, and last name
    room = models.OneToOneField(Room)
    clas = models.OneToOneField(Class)
    major = models.OneToOneField(Major)
    # major = models.

    # social media accounts

    slug = AutoSlugField(populate_from='user', unique=True)

Jason D Yeomans's avatar
Jason D Yeomans committed
24
    def profile_image_url(self):
25 26
        fb_uid = SocialAccount.objects.filter(user=self.user.id, provider='facebook')
        print("profile_image")
Jason D Yeomans's avatar
Jason D Yeomans committed
27

28 29
        if len(fb_uid)>0:
            return "http://graph.facebook.com/{}/picture?width=175&height=175".format(fb_uid[0].uid)
Jason D Yeomans's avatar
Jason D Yeomans committed
30

31
        return "http://www.gravatar.com/avatar/{}?s=175".format(hashlib.md5(self.user.email).hexdigest())
Jason D Yeomans's avatar
Jason D Yeomans committed
32 33


34 35
    def __str__(self):              # __unicode__ on Python 2
        return self.user.username