From: David Kerkeslager Date: Fri, 4 Mar 2022 16:10:37 +0000 (-0500) Subject: Add a user profile X-Git-Url: https://code.kerkeslager.com/?a=commitdiff_plain;h=637c8aa02f97e70453c659008783ecba1923b96c;p=climbing.kerkeslager.com Add a user profile --- diff --git a/src/core/settings.py b/src/core/settings.py index c07823b..f338b7a 100644 --- a/src/core/settings.py +++ b/src/core/settings.py @@ -40,6 +40,7 @@ INSTALLED_APPS = [ 'climbing', 'nutrition', 'training', + 'user_profile', 'core', ] diff --git a/src/core/urls.py b/src/core/urls.py index 8eef687..068df05 100644 --- a/src/core/urls.py +++ b/src/core/urls.py @@ -19,6 +19,7 @@ from django.urls import include, path from climbing import urls as climbing_urls from nutrition import urls as nutrition_urls from training import urls as training_urls +from user_profile import urls as user_profile_urls from . import views @@ -28,4 +29,5 @@ urlpatterns = ( path('c/', include(climbing_urls)), path('n/', include(nutrition_urls)), path('t/', include(training_urls)), + path('u/', include(user_profile_urls)), ) diff --git a/src/user_profile/__init__.py b/src/user_profile/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/user_profile/admin.py b/src/user_profile/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/src/user_profile/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/src/user_profile/apps.py b/src/user_profile/apps.py new file mode 100644 index 0000000..fe0436b --- /dev/null +++ b/src/user_profile/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UserProfileConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'user_profile' diff --git a/src/user_profile/migrations/0001_initial.py b/src/user_profile/migrations/0001_initial.py new file mode 100644 index 0000000..524329a --- /dev/null +++ b/src/user_profile/migrations/0001_initial.py @@ -0,0 +1,25 @@ +# Generated by Django 4.0.3 on 2022-03-04 16:08 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='UserProfile', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('notes', models.TextField(blank=True, null=True)), + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/src/user_profile/migrations/__init__.py b/src/user_profile/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/user_profile/models.py b/src/user_profile/models.py new file mode 100644 index 0000000..a98a009 --- /dev/null +++ b/src/user_profile/models.py @@ -0,0 +1,15 @@ +from django.contrib.auth.models import User +from django.db import models +from django.db.models.signals import post_save +from django.dispatch import receiver + +class UserProfile(models.Model): + user = models.OneToOneField(User, on_delete=models.CASCADE) + notes = models.TextField(blank=True, null=True) + + def __str__(self): + return self.user.username + +@receiver(post_save, sender=User) +def create_profile(sender, instance, **kwargs): + profile, created = UserProfile.objects.get_or_create(user=instance) diff --git a/src/user_profile/tests.py b/src/user_profile/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/src/user_profile/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/src/user_profile/urls.py b/src/user_profile/urls.py new file mode 100644 index 0000000..bc2c6d8 --- /dev/null +++ b/src/user_profile/urls.py @@ -0,0 +1,11 @@ +from django.urls import path + +from . import views + +urlpatterns = ( + path( + '', + views.user_profile_detail, + name='user-profile-detail', + ), +) diff --git a/src/user_profile/views.py b/src/user_profile/views.py new file mode 100644 index 0000000..408880e --- /dev/null +++ b/src/user_profile/views.py @@ -0,0 +1,8 @@ +from django.views.generic.detail import DetailView + +from . import models + +class UserProfileDetailView(DetailView): + model = models.UserProfile + +user_profile_detail = UserProfileDetailView.as_view()