diff --git a/source/lostplaces/lostplaces/settings.py b/source/lostplaces/lostplaces/settings.py index 921a9ca..3479c2e 100644 --- a/source/lostplaces/lostplaces/settings.py +++ b/source/lostplaces/lostplaces/settings.py @@ -126,3 +126,6 @@ STATICFILES_DIRS = [ MEDIA_URL = '/uploads/' MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads') + +# Use custom user model +AUTH_USER_MODEL = 'lostplaces_app.Explorer' diff --git a/source/lostplaces/lostplaces_app/admin.py b/source/lostplaces/lostplaces_app/admin.py index 3b933d6..2da6230 100644 --- a/source/lostplaces/lostplaces_app/admin.py +++ b/source/lostplaces/lostplaces_app/admin.py @@ -1,7 +1,20 @@ from django.contrib import admin +from django.contrib.auth import get_user_model +from django.contrib.auth.admin import UserAdmin from .models import * +from .forms import ExplorerCreationForm, ExplorerChangeForm +from .models import Explorer + # Register your models here. +class ExplorerAdmin(UserAdmin): + add_form = ExplorerCreationForm + form = ExplorerChangeForm + model = Explorer + list_display = ['email', 'username',] + +admin.site.register(Explorer, ExplorerAdmin) + admin.site.register(Place) admin.site.register(PlaceImage) \ No newline at end of file diff --git a/source/lostplaces/lostplaces_app/forms.py b/source/lostplaces/lostplaces_app/forms.py new file mode 100644 index 0000000..fc99edc --- /dev/null +++ b/source/lostplaces/lostplaces_app/forms.py @@ -0,0 +1,15 @@ +from django import forms +from django.contrib.auth.forms import UserCreationForm, UserChangeForm +from .models import Explorer + +class ExplorerCreationForm(UserCreationForm): + + class Meta: + model = Explorer + fields = ('username', 'email') + +class ExplorerChangeForm(UserChangeForm): + + class Meta: + model = Explorer + fields = ('username', 'email') diff --git a/source/lostplaces/lostplaces_app/models.py b/source/lostplaces/lostplaces_app/models.py index c807159..426ad0b 100644 --- a/source/lostplaces/lostplaces_app/models.py +++ b/source/lostplaces/lostplaces_app/models.py @@ -3,10 +3,20 @@ import uuid from django.db import models from django.dispatch import receiver +from django.contrib.auth.models import AbstractUser from django_thumbs.fields import ImageThumbsField # Create your models here. +# Usermodel +class Explorer(AbstractUser): + pass + # add additional fields in here + + def __str__(self): + return self.username + +# Place defines a lost place (location, name, description etc.). class Place (models.Model): name = models.CharField(max_length=50) location = models.CharField(max_length=50) @@ -17,6 +27,7 @@ class Place (models.Model): def __str__(self): return self.name +# Define callback that generates /path/to/image.ext as filename. def generate_image_upload_path(instance, filename): return 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1]