Start user profiles

This commit is contained in:
Michal Čihař 2012-03-02 14:24:39 +01:00
parent 98a6d92c3f
commit 26e5773271
4 changed files with 35 additions and 0 deletions

0
accounts/__init__.py Normal file
View File

18
accounts/models.py Normal file
View File

@ -0,0 +1,18 @@
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save, pre_save
class Profile(models.Model):
user = models.ForeignKey(User, unique = True)
def create_profile_callback(sender, **kwargs):
'''
Automatically create profile when creating new user.
'''
if kwargs['created']:
profile, newprofile = Profile.objects.get_or_create(user = kwargs['instance'])
if newprofile:
profile.save
post_save.connect(create_profile_callback, sender = User)

16
accounts/tests.py Normal file
View File

@ -0,0 +1,16 @@
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)

1
accounts/views.py Normal file
View File

@ -0,0 +1 @@
# Create your views here.