From 6f15a6fa068d5e0026c59e63e48bb7eb18855115 Mon Sep 17 00:00:00 2001 From: David Kerkeslager Date: Fri, 4 Mar 2022 11:14:28 -0500 Subject: [PATCH] Some admin and related name stuff for user profiles --- src/user_profile/admin.py | 6 +++++- .../migrations/0002_related_name.py | 21 +++++++++++++++++++ src/user_profile/models.py | 6 +++++- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/user_profile/migrations/0002_related_name.py diff --git a/src/user_profile/admin.py b/src/user_profile/admin.py index 8c38f3f..44bca6e 100644 --- a/src/user_profile/admin.py +++ b/src/user_profile/admin.py @@ -1,3 +1,7 @@ from django.contrib import admin -# Register your models here. +from . import models + +class UserProfileAdmin(admin.ModelAdmin): + pass +admin.site.register(models.UserProfile, UserProfileAdmin) diff --git a/src/user_profile/migrations/0002_related_name.py b/src/user_profile/migrations/0002_related_name.py new file mode 100644 index 0000000..d79e0d2 --- /dev/null +++ b/src/user_profile/migrations/0002_related_name.py @@ -0,0 +1,21 @@ +# Generated by Django 4.0.3 on 2022-03-04 16:13 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('user_profile', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='userprofile', + name='user', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/src/user_profile/models.py b/src/user_profile/models.py index a98a009..7aeb9bf 100644 --- a/src/user_profile/models.py +++ b/src/user_profile/models.py @@ -4,7 +4,11 @@ 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) + user = models.OneToOneField( + User, + on_delete=models.CASCADE, + related_name='profile', + ) notes = models.TextField(blank=True, null=True) def __str__(self): -- 2.20.1