mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-04-07 16:51:01 +00:00
git-svn-id: http://django-avatar.googlecode.com/svn/trunk@2 c76b2324-5f53-0410-85ac-b1078a54aeeb
31 lines
No EOL
864 B
Python
31 lines
No EOL
864 B
Python
import os.path
|
|
|
|
from django.db import models
|
|
from django.contrib.auth.models import User
|
|
|
|
try:
|
|
from hashlib import md5
|
|
except ImportError:
|
|
from md5 import new as md5
|
|
|
|
RATING_CHOICES = (
|
|
('g', 'G'),
|
|
('pg', 'PG'),
|
|
('r', 'R'),
|
|
('x', 'X'),
|
|
)
|
|
|
|
class Avatar(models.Model):
|
|
email_hash = models.CharField(max_length=128, blank=True)
|
|
user = models.OneToOneField(User)
|
|
# This should have a subdirectory of each user's avatar, but first we need
|
|
# patch #5361 to land into Trunk.
|
|
avatar = models.FileField(upload_to='avatars/', default='DEFAULT')
|
|
rating = models.CharField(choices=RATING_CHOICES, max_length=2, default='g')
|
|
|
|
def __unicode__(self):
|
|
return u'Gravatar for %s' % self.user
|
|
|
|
def save(self):
|
|
self.email_hash = md5(self.user.email).hexdigest().lower()
|
|
super(Avatar, self).save() |