Added CustomUser model called Explorer.
This commit is contained in:
parent
e14e4cda4c
commit
2897696663
@ -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'
|
||||
|
@ -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)
|
15
source/lostplaces/lostplaces_app/forms.py
Normal file
15
source/lostplaces/lostplaces_app/forms.py
Normal 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')
|
@ -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]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user