Support for actually setting an avatar and note on the user in the admin

This commit is contained in:
Danielle McLean 2017-10-23 11:53:51 +11:00
parent 24c83674ba
commit c22e807fa4
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
3 changed files with 15 additions and 4 deletions

View file

@ -137,6 +137,9 @@ COMPRESS_PRECOMPILERS = (
('text/stylus', os.path.join(BASE_DIR, 'node_modules', '.bin', 'stylus') + ' {infile} -o {outfile}'), ('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 # Settings specific to lemoncurry
LEMONCURRY_SITE_NAME = '00dani.me' LEMONCURRY_SITE_NAME = '00dani.me'

View file

@ -1,8 +1,12 @@
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.models import Group from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.admin import UserAdmin
from .models import User from .models import User
class UserAdmin(BaseUserAdmin):
fieldsets = BaseUserAdmin.fieldsets + (
('Profile', {'fields': ('avatar', 'note')}),
)
admin.site.register(User, UserAdmin) admin.site.register(User, UserAdmin)
admin.site.unregister(Group)

View file

@ -2,6 +2,10 @@ from django.db import models
from django.contrib.auth.models import AbstractUser 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): class User(AbstractUser):
avatar = models.ImageField() avatar = models.ImageField(upload_to=avatar_path)
note = models.TextField(blank=True) note = models.TextField(blank=True)