diff --git a/backend/accounts/models.py b/backend/accounts/models.py index be96577..6fe4041 100644 --- a/backend/accounts/models.py +++ b/backend/accounts/models.py @@ -19,7 +19,7 @@ class CustomUser(AbstractUser): null=True, upload_to='avatars/') 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 def full_name(self): @@ -29,9 +29,6 @@ class CustomUser(AbstractUser): def admin_url(self): 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 diff --git a/backend/api/urls.py b/backend/api/urls.py index b92de4d..86fa82f 100644 --- a/backend/api/urls.py +++ b/backend/api/urls.py @@ -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 config import settings urlpatterns = [ 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 += static( - settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + 'media/', document_root=settings.MEDIA_ROOT) diff --git a/backend/config/settings.py b/backend/config/settings.py index 61487df..1af16ad 100644 --- a/backend/config/settings.py +++ b/backend/config/settings.py @@ -93,7 +93,6 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" MEDIA_URL = 'api/v1/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') - ROOT_URLCONF = 'config.urls' TEMPLATES = [