Added CustomUser model called Explorer.

This commit is contained in:
Marcus Scholz 2020-07-28 20:15:34 +02:00
parent e14e4cda4c
commit 2897696663
4 changed files with 42 additions and 0 deletions

View File

@ -126,3 +126,6 @@ STATICFILES_DIRS = [
MEDIA_URL = '/uploads/' MEDIA_URL = '/uploads/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads') MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
# Use custom user model
AUTH_USER_MODEL = 'lostplaces_app.Explorer'

View File

@ -1,7 +1,20 @@
from django.contrib import admin from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin
from .models import * from .models import *
from .forms import ExplorerCreationForm, ExplorerChangeForm
from .models import Explorer
# Register your models here. # 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(Place)
admin.site.register(PlaceImage) admin.site.register(PlaceImage)

View File

@ -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')

View File

@ -3,10 +3,20 @@ import uuid
from django.db import models from django.db import models
from django.dispatch import receiver from django.dispatch import receiver
from django.contrib.auth.models import AbstractUser
from django_thumbs.fields import ImageThumbsField from django_thumbs.fields import ImageThumbsField
# Create your models here. # 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): class Place (models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
location = models.CharField(max_length=50) location = models.CharField(max_length=50)
@ -17,6 +27,7 @@ class Place (models.Model):
def __str__(self): def __str__(self):
return self.name return self.name
# Define callback that generates /path/to/image.ext as filename.
def generate_image_upload_path(instance, filename): def generate_image_upload_path(instance, filename):
return 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1] return 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1]