2012-08-28 18:44:51 +02:00
|
|
|
from django.db import models
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.db.models.signals import post_save
|
|
|
|
|
|
|
|
class UserProfile(models.Model):
|
|
|
|
user = models.OneToOneField(User)
|
|
|
|
pointer = models.IntegerField()
|
|
|
|
|
|
|
|
class ZephyrClass(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
|
|
|
|
2012-08-28 21:27:42 +02:00
|
|
|
class Recipient(models.Model):
|
|
|
|
user_or_class = models.IntegerField()
|
|
|
|
type = models.CharField(max_length=30)
|
|
|
|
|
2012-08-28 18:44:51 +02:00
|
|
|
class Zephyr(models.Model):
|
|
|
|
sender = models.ForeignKey(UserProfile)
|
2012-08-28 21:27:42 +02:00
|
|
|
recipient = models.ForeignKey(Recipient) # personal or class
|
2012-08-28 18:44:51 +02:00
|
|
|
instance = models.CharField(max_length=30)
|
|
|
|
content = models.CharField(max_length=200)
|
|
|
|
pub_date = models.DateTimeField('date published')
|
|
|
|
|
2012-08-28 23:12:14 +02:00
|
|
|
def create_user_profile(**kwargs):
|
2012-08-28 18:44:51 +02:00
|
|
|
"""When creating a new user, make a profile for him or her."""
|
|
|
|
u = kwargs["instance"]
|
|
|
|
if not UserProfile.objects.filter(user=u):
|
|
|
|
UserProfile(user=u, pointer=-1).save()
|
|
|
|
post_save.connect(create_user_profile, sender=User)
|