Mercurial > public > sg101
view gpp/bio/models.py @ 19:aa2b41c5212b
First steps at scratching out a home page. Will need to develop some template tags now to fill it out.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 19 Apr 2009 20:10:00 +0000 |
parents | dbd703f7d63a |
children | 5eed5e7c1c98 |
line wrap: on
line source
""" Contains models for the bio application. I would have picked profile for this application, but that is already taken, apparently. """ import os.path from django.db import models from django.contrib import auth from django.conf import settings from django.template.loader import render_to_string def avatar_file_path_for_user(username, filename): return os.path.join(settings.AVATAR_DIR, 'users', username, filename) def avatar_file_path(instance, filename): return avatar_file_path_for_user(instance.user.username, filename) class UserProfile(models.Model): """model to represent additional information about users""" user = models.ForeignKey(auth.models.User, unique=True) location = models.CharField(max_length=128, blank=True) birthday = models.DateField(blank=True, null=True, help_text='Optional; the year is not shown to others') occupation = models.CharField(max_length=128, blank=True) interests = models.CharField(max_length=255, blank=True) website_1 = models.URLField(verify_exists=False, blank=True) website_2 = models.URLField(verify_exists=False, blank=True) website_3 = models.URLField(verify_exists=False, blank=True) profile_text = models.TextField(blank=True) profile_html = models.TextField(blank=True) hide_email = models.BooleanField(default=True) icq = models.CharField('ICQ', max_length=15, blank=True) aim = models.CharField('AIM', max_length=18, blank=True) yim = models.CharField('YIM', max_length=25, blank=True) msnm = models.CharField('MSN', max_length=25, blank=True) twitter = models.CharField(max_length=64, blank=True) signature = models.TextField(blank=True) signature_html = models.TextField(blank=True) avatar = models.ImageField(upload_to=avatar_file_path, blank=True) def __unicode__(self): return self.user.username class Meta: ordering = ('user__username', ) def save(self, *args, **kwargs): html = render_to_string('bio/markdown.html', {'data': self.profile_text}) self.profile_html = html.strip() html = render_to_string('bio/markdown.html', {'data': self.signature}) self.signature_html = html.strip() super(UserProfile, self).save(*args, **kwargs) # vim: ts=4 sw=4