models.py 1.15 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 25 26 27 28 29 30 31 32
    def profile_image_url(self):
        fb_uid = SocialAccount.objects.filter(user_id=self.user.id, provider='facebook')

        if len(fb_uid):
            return "http://graph.facebook.com/{}/picture?width=40&height=40".format(fb_uid[0].uid)

            return "http://www.gravatar.com/avatar/{}?s=40".format(hashlib.md5(self.user.email).hexdigest())


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