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

Infra Setup and Media file upload #1

Merged
merged 17 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Backend media file upload without API
  • Loading branch information
SparshRawal committed Dec 9, 2020
commit 8fe75d3d6498a8c7fb0dfd8f5ee16031f9e59347
8 changes: 8 additions & 0 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"""

from pathlib import Path
import os


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -37,6 +39,9 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'uploads',

]

MIDDLEWARE = [
Expand Down Expand Up @@ -118,3 +123,6 @@
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'

MEDIA_ROOT=os.path.join(BASE_DIR,'media')
MEDIA_URL='/media/'
4 changes: 4 additions & 0 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

from django.contrib import admin
from django.urls import path
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
path('admin/', admin.site.urls),
]

urlpatterns+=static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Django==3.1.4
djangorestframework==3.12.2
Empty file added backend/uploads/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions backend/uploads/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin

# Register your models here.
from .models import upload

admin.site.register(upload)
5 changes: 5 additions & 0 deletions backend/uploads/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class UploadsConfig(AppConfig):
name = 'uploads'
8 changes: 8 additions & 0 deletions backend/uploads/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.db import models

def upload_path(instance,filename):
return '/'.join(['user audio',str(instance.name),filename])
# Create your models here.
class upload(models.Model):
name=models.CharField(max_length=32)
audio=models.FileField(upload_to=upload_path)
3 changes: 3 additions & 0 deletions backend/uploads/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions backend/uploads/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.