handle media and static files for uploads
This commit is contained in:
parent
75c931eb74
commit
2d5d70972f
3 changed files with 21 additions and 3 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
@ -136,6 +137,6 @@ class AbsenceAttachment(models.Model):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
id: uuid.UUID = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False, max_length=36)
|
id: uuid.UUID = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False, max_length=36)
|
||||||
content = models.FileField()
|
content = models.FileField(upload_to="absence/attachment/")
|
||||||
|
|
||||||
absence = models.ForeignKey(to=Absence, on_delete=models.CASCADE, related_name="attachments")
|
absence = models.ForeignKey(to=Absence, on_delete=models.CASCADE, related_name="attachments")
|
||||||
|
|
|
@ -131,7 +131,13 @@ USE_TZ = True
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = "static/"
|
||||||
|
STATIC_ROOT = BASE_DIR / "static-collected/"
|
||||||
|
|
||||||
|
# Media files
|
||||||
|
|
||||||
|
MEDIA_URL = "media/"
|
||||||
|
MEDIA_ROOT = BASE_DIR / "media/"
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||||
|
|
|
@ -15,7 +15,11 @@ Including another URLconf
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include, re_path
|
||||||
|
from django.views.static import serve
|
||||||
|
|
||||||
|
from Palto import settings
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# Application
|
# Application
|
||||||
|
@ -28,3 +32,10 @@ urlpatterns = [
|
||||||
path('admin/', admin.site.urls), # Admin page
|
path('admin/', admin.site.urls), # Admin page
|
||||||
path("__debug__/", include("debug_toolbar.urls")), # Debug toolbar
|
path("__debug__/", include("debug_toolbar.urls")), # Debug toolbar
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
if settings.DEBUG:
|
||||||
|
urlpatterns += [
|
||||||
|
re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}),
|
||||||
|
re_path(r'^static/(?P<path>.*)$', serve, {'document_root': settings.STATIC_ROOT}),
|
||||||
|
]
|
||||||
|
|
Loading…
Reference in a new issue