#59 Pictures are in the wrong directory
This commit is contained in:
		
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -94,3 +94,6 @@ venv.bak/
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# Django Migrations for Development branches
 | 
					# Django Migrations for Development branches
 | 
				
			||||||
django_lostplaces/lostplaces/migrations/*
 | 
					django_lostplaces/lostplaces/migrations/*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Django Static files
 | 
				
			||||||
 | 
					django_lostplaces/static/*
 | 
				
			||||||
@@ -32,7 +32,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 | 
				
			|||||||
SECRET_KEY = 'n$(bx8(^)*wz1ygn@-ekt7rl^1km*!_c+fwwjiua8m@-x_rpl0'
 | 
					SECRET_KEY = 'n$(bx8(^)*wz1ygn@-ekt7rl^1km*!_c+fwwjiua8m@-x_rpl0'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# SECURITY WARNING: don't run with debug turned on in production!
 | 
					# SECURITY WARNING: don't run with debug turned on in production!
 | 
				
			||||||
DEBUG = True
 | 
					DEBUG = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ALLOWED_HOSTS = ['localhost']
 | 
					ALLOWED_HOSTS = ['localhost']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -145,15 +145,16 @@ LANGUAGES = [
 | 
				
			|||||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
 | 
					# https://docs.djangoproject.com/en/3.1/howto/static-files/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
STATIC_URL = '/static/'
 | 
					STATIC_URL = '/static/'
 | 
				
			||||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
 | 
					STATIC_ROOT = os.path.join(BASE_DIR, 'static')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Upload directory
 | 
					# Upload directory
 | 
				
			||||||
MEDIA_URL = '/uploads/'
 | 
					MEDIA_URL = '/uploads/'
 | 
				
			||||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
 | 
					MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads/')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Thumbnails
 | 
					# Thumbnails
 | 
				
			||||||
THUMBNAIL_MEDIA_ROOT = os.path.join(MEDIA_ROOT, 'thumbs/')
 | 
					RELATIVE_THUMBNAIL_PATH = 'images/'
 | 
				
			||||||
THUMBNAIL_MEDIA_URL = os.path.join(MEDIA_URL, 'thumbs/')
 | 
					THUMBNAIL_MEDIA_ROOT = os.path.join(MEDIA_ROOT, RELATIVE_THUMBNAIL_PATH)
 | 
				
			||||||
 | 
					THUMBNAIL_MEDIA_URL = os.path.join(MEDIA_URL, RELATIVE_THUMBNAIL_PATH)
 | 
				
			||||||
THUMBNAIL_QUALITY = 75
 | 
					THUMBNAIL_QUALITY = 75
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Templates to use for authentication
 | 
					# Templates to use for authentication
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,9 @@ Including another URLconf
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
from django.contrib import admin
 | 
					from django.contrib import admin
 | 
				
			||||||
from django.conf import settings
 | 
					from django.conf import settings
 | 
				
			||||||
 | 
					from django.views.static import serve
 | 
				
			||||||
from django.conf.urls.static import static
 | 
					from django.conf.urls.static import static
 | 
				
			||||||
 | 
					from django.conf.urls import url
 | 
				
			||||||
from django.urls import path, include
 | 
					from django.urls import path, include
 | 
				
			||||||
from django.views.generic.base import TemplateView
 | 
					from django.views.generic.base import TemplateView
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -30,4 +32,6 @@ urlpatterns = [
 | 
				
			|||||||
    path('signup/', SignUpView.as_view(), name='signup'),
 | 
					    path('signup/', SignUpView.as_view(), name='signup'),
 | 
				
			||||||
    path('explorer/', include('django.contrib.auth.urls')),
 | 
					    path('explorer/', include('django.contrib.auth.urls')),
 | 
				
			||||||
    path('', include('lostplaces.urls')),
 | 
					    path('', include('lostplaces.urls')),
 | 
				
			||||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
 | 
					    url(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}),
 | 
				
			||||||
 | 
					    url(r'^uploads/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT})
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@ from django.urls import reverse
 | 
				
			|||||||
from django.dispatch import receiver
 | 
					from django.dispatch import receiver
 | 
				
			||||||
from django.db.models.signals import post_delete, pre_save
 | 
					from django.db.models.signals import post_delete, pre_save
 | 
				
			||||||
from django.utils.translation import ugettext_lazy as _
 | 
					from django.utils.translation import ugettext_lazy as _
 | 
				
			||||||
 | 
					from django.conf import settings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from lostplaces.models.abstract_models import Submittable, Taggable, Mapable, Expireable
 | 
					from lostplaces.models.abstract_models import Submittable, Taggable, Mapable, Expireable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -120,7 +121,7 @@ def generate_place_image_filename(instance, filename):
 | 
				
			|||||||
    Returns filename as: place_pk-placename{-number}.jpg
 | 
					    Returns filename as: place_pk-placename{-number}.jpg
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 'places/' + str(instance.place.pk) + '-' + str(instance.place.name) + '.' + filename.split('.')[-1]
 | 
					    return settings.RELATIVE_THUMBNAIL_PATH + str(instance.place.pk) + '-' + str(instance.place.name) + '.' + filename.split('.')[-1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def generate_image_upload_path(instance, filename):
 | 
					def generate_image_upload_path(instance, filename):
 | 
				
			||||||
    return generate_place_image_filename(instance, filename)
 | 
					    return generate_place_image_filename(instance, filename)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user