Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add media upload support #67

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions backend/accounts/migrations/0005_profile_profile_picture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.4 on 2024-10-10 16:58

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("accounts", "0004_alter_profile_options"),
]

operations = [
migrations.AddField(
model_name="profile",
name="profile_picture",
field=models.ImageField(blank=True, upload_to="profile_pictures"),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.4 on 2024-10-10 20:04

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("accounts", "0005_profile_profile_picture"),
]

operations = [
migrations.AddField(
model_name="profile",
name="first_name",
field=models.CharField(blank=True, max_length=100),
),
migrations.AddField(
model_name="profile",
name="last_name",
field=models.CharField(blank=True, max_length=100),
),
]
3 changes: 3 additions & 0 deletions backend/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ def __str__(self):

class Profile(models.Model):
user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
first_name = models.CharField(max_length=100, blank=True)
last_name = models.CharField(max_length=100, blank=True)
follows = models.ManyToManyField(
"self", related_name="followers", symmetrical=False, blank=True
)
profile_picture = models.ImageField(upload_to="profile_pictures", blank=True)

def __str__(self):
return f" {self.user.username} - Profile"
Expand Down
4 changes: 2 additions & 2 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class ProfileList(generics.ListAPIView):
serializer_class = ProfileSerializer


class ProfileDetail(generics.RetrieveAPIView):
class ProfileDetail(generics.RetrieveUpdateAPIView):
"""
View to view details of a profile
View to view or update profile details

"""

Expand Down
4 changes: 4 additions & 0 deletions backend/chitchat/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@

STATIC_URL = "static/"

# Media files (Images, Videos)
MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "media"

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

Expand Down
7 changes: 7 additions & 0 deletions backend/chitchat/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
Expand Down Expand Up @@ -48,3 +51,7 @@
),
path("redoc/", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc"),
]


if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Binary file modified backend/requirements.txt
Binary file not shown.
Loading