Skip to content

Commit

Permalink
image 등록가능
Browse files Browse the repository at this point in the history
  • Loading branch information
YSHyeonn committed Feb 17, 2024
1 parent 4198356 commit 982395c
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 39 deletions.
Binary file removed app/_image/iamcrying.jpg
Binary file not shown.
Binary file removed app/_image/iamcrying_lOisVci.jpg
Binary file not shown.
Binary file removed app/_image/iamcrying_qXko0fR.jpg
Binary file not shown.
3 changes: 3 additions & 0 deletions app/cspc_web/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@
STATIC_URL = "/djang_static/"
STATIC_ROOT = os.path.join(BASE_DIR, "static")

# MEDIA_URL = "/media/"

# MEDIA_ROOT = os.path.join(BASE_DIR, "media")

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
Expand Down
2 changes: 1 addition & 1 deletion app/cspc_web/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
path("admin/", admin.site.urls),
path("api/apply/", include("apply.urls")),
path("api/user/", include("user.urls")),
path("api/image/", include("image.urls")),
# path("api/image/", include("image.urls")),
re_path(
r"^swagger(?P<format>\.json|\.yaml)$",
schema_view.without_ui(cache_timeout=0),
Expand Down
9 changes: 7 additions & 2 deletions app/image/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from django.contrib import admin
from .models import Image
from .models import *

# Register your models here.

admin.site.register(Image)
admin.site.register(Apply_Image)
admin.site.register(Introduce_Image)
admin.site.register(Login_Image)
admin.site.register(Main_Image)
admin.site.register(NotAllow_Image)
admin.site.register(Result_Image)
18 changes: 18 additions & 0 deletions app/image/migrations/0002_alter_image_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.5 on 2024-02-17 15:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('image', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='image',
name='image',
field=models.ImageField(upload_to='media'),
),
]
16 changes: 16 additions & 0 deletions app/image/migrations/0003_delete_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.1.5 on 2024-02-17 15:58

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('image', '0002_alter_image_image'),
]

operations = [
migrations.DeleteModel(
name='Image',
),
]
69 changes: 69 additions & 0 deletions app/image/migrations/0004_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Generated by Django 4.1.5 on 2024-02-17 16:40

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('image', '0003_delete_image'),
]

operations = [
migrations.CreateModel(
name='Apply_Image',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('image', models.ImageField(upload_to='media/Apply')),
('uploaded_at', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='Introduce_Image',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('image', models.ImageField(upload_to='media/Introduce')),
('uploaded_at', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='Login_Image',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('image', models.ImageField(upload_to='media/Login')),
('uploaded_at', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='Main_Image',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('image', models.ImageField(upload_to='media/Main')),
('uploaded_at', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='NotAllow_Image',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('image', models.ImageField(upload_to='media/NotAllow')),
('uploaded_at', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='Result_Image',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('image', models.ImageField(upload_to='media/Result')),
('uploaded_at', models.DateTimeField(auto_now_add=True)),
],
),
]
69 changes: 66 additions & 3 deletions app/image/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,73 @@
# Create your models here.


class Image(models.Model):
title = models.CharField(max_length=50)
image = models.ImageField(upload_to="_image/")
class Apply_Image(models.Model):
title = models.CharField(null=False, max_length=50)
image = models.ImageField(null=False, upload_to="media/Apply")
uploaded_at = models.DateTimeField(auto_now_add=True)

class Meta:
app_label = "image"

def __str__(self):
return self.title


class Introduce_Image(models.Model):
title = models.CharField(null=False, max_length=50)
image = models.ImageField(null=False, upload_to="media/Introduce")
uploaded_at = models.DateTimeField(auto_now_add=True)

class Meta:
app_label = "image"

def __str__(self):
return self.title


class Login_Image(models.Model):
title = models.CharField(null=False, max_length=50)
image = models.ImageField(null=False, upload_to="media/Login")
uploaded_at = models.DateTimeField(auto_now_add=True)

class Meta:
app_label = "image"

def __str__(self):
return self.title


class Main_Image(models.Model):
title = models.CharField(null=False, max_length=50)
image = models.ImageField(null=False, upload_to="media/Main")
uploaded_at = models.DateTimeField(auto_now_add=True)

class Meta:
app_label = "image"

def __str__(self):
return self.title


class NotAllow_Image(models.Model):
title = models.CharField(null=False, max_length=50)
image = models.ImageField(null=False, upload_to="media/NotAllow")
uploaded_at = models.DateTimeField(auto_now_add=True)

class Meta:
app_label = "image"

def __str__(self):
return self.title


class Result_Image(models.Model):
title = models.CharField(null=False, max_length=50)
image = models.ImageField(null=False, upload_to="media/Result")
uploaded_at = models.DateTimeField(auto_now_add=True)

class Meta:
app_label = "image"

def __str__(self):
return self.title
12 changes: 10 additions & 2 deletions app/image/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from rest_framework import serializers
from .models import Image
from .models import *
from django.apps import apps


class ImageSerializer(serializers.ModelSerializer):

class Meta:
model = Image
model = None
fields = ["id", "title", "image", "uploaded_at"]

def __init__(self, *args, **kwargs):
model_name = kwargs.pop("model_name", None)
if model_name:
self.Meta.model = apps.get_model("image", model_name)
super().__init__(*args, **kwargs)
12 changes: 6 additions & 6 deletions app/image/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.urls import path
from .views import ImageUploadView
from image.views import *
# from django.urls import path
# from .views import ImageUploadView
# from image.views import *

urlpatterns = [
path("image_test/", ImageUploadView.as_view(), name="image-upload"),
]
# urlpatterns = [
# path("image_test/", ImageUploadView.as_view(), name="image-upload"),
# ]
39 changes: 14 additions & 25 deletions app/image/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rest_framework.parsers import MultiPartParser, FormParser
from rest_framework.response import Response
from rest_framework.views import APIView
from .models import Image
from .models import *
from .serializers import ImageSerializer
from swagger_response import *

Expand All @@ -12,28 +12,17 @@
from rest_framework.permissions import IsAuthenticated


class ImageUploadView(APIView):
parser_classes = (MultiPartParser, FormParser)
authentication_classes = [BasicAuthentication]
permission_classes = [IsAuthenticated]
# class ImageUploadView(APIView):
# parser_classes = (MultiPartParser, FormParser)
# authentication_classes = [BasicAuthentication]
# permission_classes = [IsAuthenticated]

@swagger_auto_schema(request_body=ImageSerializer)
def post(self, request):
if request.user.is_authenticated:
image_serializer = ImageSerializer(data=request.data)
if image_serializer.is_valid():
image_serializer.save()
return Response(image_serializer.data, status=200)
else:
return Response(image_serializer.errors, status=400)

@swagger_auto_schema(
responses=get_image_response, authentication_classes=[BasicAuthentication]
)
def get(self, request):
if request.user.is_authenticated:
image = Image.objects.all()
serializer = ImageSerializer(image, many=True)
return Response(serializer.data, status=200)
else:
return Response(status=401)
# @swagger_auto_schema(request_body=ImageSerializer)
# def post(self, request):
# if request.user.is_authenticated:
# image_serializer = ImageSerializer(data=request.data)
# if image_serializer.is_valid():
# image_serializer.save()
# return Response(image_serializer.data, status=200)
# else:
# return Response(image_serializer.errors, status=400)

0 comments on commit 982395c

Please sign in to comment.