'climbing',
'nutrition',
'training',
+ 'user_profile',
'core',
]
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
path('c/', include(climbing_urls)),
path('n/', include(nutrition_urls)),
path('t/', include(training_urls)),
+ path('u/', include(user_profile_urls)),
)
--- /dev/null
+from django.contrib import admin
+
+# Register your models here.
--- /dev/null
+from django.apps import AppConfig
+
+
+class UserProfileConfig(AppConfig):
+ default_auto_field = 'django.db.models.BigAutoField'
+ name = 'user_profile'
--- /dev/null
+# 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)),
+ ],
+ ),
+ ]
--- /dev/null
+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)
--- /dev/null
+from django.test import TestCase
+
+# Create your tests here.
--- /dev/null
+from django.urls import path
+
+from . import views
+
+urlpatterns = (
+ path(
+ '<str:username>',
+ views.user_profile_detail,
+ name='user-profile-detail',
+ ),
+)
--- /dev/null
+from django.views.generic.detail import DetailView
+
+from . import models
+
+class UserProfileDetailView(DetailView):
+ model = models.UserProfile
+
+user_profile_detail = UserProfileDetailView.as_view()