Fix development url for media files

This commit is contained in:
Keannu Bernasol 2024-01-06 12:27:41 +08:00
parent 5f4aac696e
commit 55f16b15fe
3 changed files with 6 additions and 10 deletions

View file

@ -19,7 +19,7 @@ class CustomUser(AbstractUser):
null=True, upload_to='avatars/') null=True, upload_to='avatars/')
def avatar_url(self): def avatar_url(self):
return f'/api/v1/media/avatars/{self.avatar.name}' return f'/api/v1/media/avatars/{self.avatar.field.storage.name(self.avatar.path)}'
@property @property
def full_name(self): def full_name(self):
@ -29,9 +29,6 @@ class CustomUser(AbstractUser):
def admin_url(self): def admin_url(self):
return reverse('admin:users_customuser_change', args=(self.pk,)) return reverse('admin:users_customuser_change', args=(self.pk,))
def get_prep_value(self, value):
original_filename = self.avatar.field.storage.name(self.avatar.path)
return original_filename
pass pass

View file

@ -1,14 +1,14 @@
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.urls import path, include from django.urls import path, include
from config import settings from config import settings
urlpatterns = [ urlpatterns = [
path('accounts/', include('accounts.urls')), path('accounts/', include('accounts.urls')),
] ]
if settings.DEBUG:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf.urls.static import static
# Media files # Media files
if settings.DEBUG:
urlpatterns += staticfiles_urlpatterns() urlpatterns += staticfiles_urlpatterns()
urlpatterns += static( urlpatterns += static(
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 'media/', document_root=settings.MEDIA_ROOT)

View file

@ -93,7 +93,6 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
MEDIA_URL = 'api/v1/media/' MEDIA_URL = 'api/v1/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
ROOT_URLCONF = 'config.urls' ROOT_URLCONF = 'config.urls'
TEMPLATES = [ TEMPLATES = [