add Profile
This commit is contained in:
parent
cd02ca4684
commit
22b2bb0b82
1
profile/__init__.py
Normal file
1
profile/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
default_app_config = 'profile.apps.ProfileConfig'
|
18
profile/apps.py
Normal file
18
profile/apps.py
Normal file
@ -0,0 +1,18 @@
|
||||
from django.apps import AppConfig
|
||||
from django.dispatch import receiver
|
||||
from django.db.models.signals import post_save
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
def create_profile(sender, created, instance, **kwargs):
|
||||
from .models import Profile
|
||||
if created:
|
||||
Profile.objects.create(user=instance)
|
||||
|
||||
|
||||
class ProfileConfig(AppConfig):
|
||||
name = 'profile'
|
||||
app_label = 'profile'
|
||||
|
||||
def ready(self):
|
||||
post_save.connect(create_profile, sender=User)
|
23
profile/migrations/0001_initial.py
Normal file
23
profile/migrations/0001_initial.py
Normal file
@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Profile',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)),
|
||||
('lifting_units', models.CharField(max_length=1, choices=[('m', 'Metric (kg)'), ('i', 'Imperial (lbs)')])),
|
||||
('user', models.OneToOneField(related_name='config', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
0
profile/migrations/__init__.py
Normal file
0
profile/migrations/__init__.py
Normal file
15
profile/models.py
Normal file
15
profile/models.py
Normal file
@ -0,0 +1,15 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
UNITS = (
|
||||
('m', 'Metric (kg)'),
|
||||
('i', 'Imperial (lbs)'),
|
||||
)
|
||||
|
||||
class Profile(models.Model):
|
||||
user = models.OneToOneField(User, related_name='profile')
|
||||
|
||||
lifting_units = models.CharField(max_length=1, choices=UNITS)
|
||||
|
||||
def metric(self):
|
||||
return self.lifting_units == 'm'
|
12
profile/tests.py
Normal file
12
profile/tests.py
Normal file
@ -0,0 +1,12 @@
|
||||
from django.test import TestCase
|
||||
from django.contrib.auth.models import User
|
||||
from .models import Profile
|
||||
|
||||
|
||||
class TestProfile(TestCase):
|
||||
|
||||
def test_signal(self):
|
||||
|
||||
u = User.objects.create_user(username='test', email='test@example.com', password='test')
|
||||
|
||||
assert Profile.objects.filter(user=u).count() == 1
|
@ -21,6 +21,7 @@ INSTALLED_APPS = (
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'django_gravatar',
|
||||
'profile',
|
||||
'lifting',
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user