#2 Handling image upload

This commit is contained in:
reverend 2022-12-25 12:19:54 +01:00
parent 0f69c44cc3
commit b0d9c46eb2
4 changed files with 19 additions and 10 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
django_web_galleries/media/* django_web_galleries/media/*
django_web_galleries/static/*

View File

@ -16,7 +16,20 @@ Including another URLconf
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', include('web_galleries.urls')) path('', include('web_galleries.urls'))
] ]
if settings.DEBUG:
urlpatterns += static(
settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT
)
urlpatterns += static(
settings.STATIC_URL,
document_root=settings.STATIC_ROOT
)

View File

@ -6,4 +6,7 @@ from .models import Image
class ImageUploadForm(forms.ModelForm): class ImageUploadForm(forms.ModelForm):
class Meta: class Meta:
model = Image model = Image
fields = ['description', 'image_file', 'private'] fields = ['description', 'image_file', 'private', 'title']
labels = {
'private': 'Make this image private'
}

View File

@ -1,6 +1,4 @@
from django.urls import path from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
from .views import ( from .views import (
ImageUploadView, ImageUploadView,
@ -11,9 +9,3 @@ urlpatterns = [
path('', PublicImageListView.as_view(), name='home'), path('', PublicImageListView.as_view(), name='home'),
path('upload/', ImageUploadView.as_view(), name='upload_image') path('upload/', ImageUploadView.as_view(), name='upload_image')
] ]
if settings.DEBUG:
urlpatterns += static(
settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT
)