From c22e807fa4afaeb75c23163ee9bc0557deda2e6c Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Mon, 23 Oct 2017 11:53:51 +1100 Subject: [PATCH] Support for actually setting an avatar and note on the user in the admin --- lemoncurry/settings/base.py | 3 +++ users/admin.py | 10 +++++++--- users/models.py | 6 +++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lemoncurry/settings/base.py b/lemoncurry/settings/base.py index 9284ac2..c1e823a 100644 --- a/lemoncurry/settings/base.py +++ b/lemoncurry/settings/base.py @@ -137,6 +137,9 @@ COMPRESS_PRECOMPILERS = ( ('text/stylus', os.path.join(BASE_DIR, 'node_modules', '.bin', 'stylus') + ' {infile} -o {outfile}'), ) +MEDIA_URL = STATIC_URL + 'media/' +MEDIA_ROOT = os.path.join(STATIC_ROOT, 'media') + # Settings specific to lemoncurry LEMONCURRY_SITE_NAME = '00dani.me' diff --git a/users/admin.py b/users/admin.py index 8ee4dfe..3966363 100644 --- a/users/admin.py +++ b/users/admin.py @@ -1,8 +1,12 @@ from django.contrib import admin -from django.contrib.auth.models import Group -from django.contrib.auth.admin import UserAdmin +from django.contrib.auth.admin import UserAdmin as BaseUserAdmin from .models import User +class UserAdmin(BaseUserAdmin): + fieldsets = BaseUserAdmin.fieldsets + ( + ('Profile', {'fields': ('avatar', 'note')}), + ) + + admin.site.register(User, UserAdmin) -admin.site.unregister(Group) diff --git a/users/models.py b/users/models.py index 42b52b7..55ec906 100644 --- a/users/models.py +++ b/users/models.py @@ -2,6 +2,10 @@ from django.db import models from django.contrib.auth.models import AbstractUser +def avatar_path(instance, name): + return 'avatars/{id}/{name}'.format(id=instance.id, name=name) + + class User(AbstractUser): - avatar = models.ImageField() + avatar = models.ImageField(upload_to=avatar_path) note = models.TextField(blank=True)