From b2ba661013daa1ae88fdeef9861bb10de752f7cc Mon Sep 17 00:00:00 2001 From: AhyeonLim Date: Wed, 3 Aug 2022 15:07:31 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- myvenv/bin/activate | 2 +- myvenv/bin/activate.csh | 2 +- myvenv/bin/activate.fish | 2 +- myvenv/bin/django-admin | 2 +- myvenv/bin/pip | 2 +- myvenv/bin/pip3 | 2 +- myvenv/bin/pip3.10 | 2 +- myvenv/bin/sqlformat | 2 +- yuseo/yuseo/settings.py | 5 +++ yuseo/yuseo/urls.py | 4 +- yuseo/yuseoapp/migrations/0001_initial.py | 1 + .../migrations/0002_alter_yuseo_image.py | 18 +++++++++ yuseo/yuseoapp/models.py | 6 ++- yuseo/yuseoapp/serializers.py | 38 +++++++++++++++++-- 14 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 yuseo/yuseoapp/migrations/0002_alter_yuseo_image.py diff --git a/myvenv/bin/activate b/myvenv/bin/activate index be309df7..e38dcf8e 100644 --- a/myvenv/bin/activate +++ b/myvenv/bin/activate @@ -38,7 +38,7 @@ deactivate () { # unset irrelevant variables deactivate nondestructive -VIRTUAL_ENV="/Users/ahyeonlim/YUSEO-Server/myvenv" +VIRTUAL_ENV="/Users/ahyeonlim/Otr-Server/myvenv" export VIRTUAL_ENV _OLD_VIRTUAL_PATH="$PATH" diff --git a/myvenv/bin/activate.csh b/myvenv/bin/activate.csh index ffdfb5bf..46189263 100644 --- a/myvenv/bin/activate.csh +++ b/myvenv/bin/activate.csh @@ -8,7 +8,7 @@ alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PA # Unset irrelevant variables. deactivate nondestructive -setenv VIRTUAL_ENV "/Users/ahyeonlim/YUSEO-Server/myvenv" +setenv VIRTUAL_ENV "/Users/ahyeonlim/Otr-Server/myvenv" set _OLD_VIRTUAL_PATH="$PATH" setenv PATH "$VIRTUAL_ENV/bin:$PATH" diff --git a/myvenv/bin/activate.fish b/myvenv/bin/activate.fish index a81592e8..1ee7c5f5 100644 --- a/myvenv/bin/activate.fish +++ b/myvenv/bin/activate.fish @@ -30,7 +30,7 @@ end # Unset irrelevant variables. deactivate nondestructive -set -gx VIRTUAL_ENV "/Users/ahyeonlim/YUSEO-Server/myvenv" +set -gx VIRTUAL_ENV "/Users/ahyeonlim/Otr-Server/myvenv" set -gx _OLD_VIRTUAL_PATH $PATH set -gx PATH "$VIRTUAL_ENV/bin" $PATH diff --git a/myvenv/bin/django-admin b/myvenv/bin/django-admin index 541a0f8f..6df12e0e 100755 --- a/myvenv/bin/django-admin +++ b/myvenv/bin/django-admin @@ -1,4 +1,4 @@ -#!/Users/ahyeonlim/YUSEO-Server/myvenv/bin/python3 +#!/Users/ahyeonlim/Otr-Server/myvenv/bin/python3 # -*- coding: utf-8 -*- import re import sys diff --git a/myvenv/bin/pip b/myvenv/bin/pip index f942e440..bde8aded 100755 --- a/myvenv/bin/pip +++ b/myvenv/bin/pip @@ -1,4 +1,4 @@ -#!/Users/ahyeonlim/YUSEO-Server/myvenv/bin/python3 +#!/Users/ahyeonlim/Otr-Server/myvenv/bin/python3 # -*- coding: utf-8 -*- import re import sys diff --git a/myvenv/bin/pip3 b/myvenv/bin/pip3 index f942e440..bde8aded 100755 --- a/myvenv/bin/pip3 +++ b/myvenv/bin/pip3 @@ -1,4 +1,4 @@ -#!/Users/ahyeonlim/YUSEO-Server/myvenv/bin/python3 +#!/Users/ahyeonlim/Otr-Server/myvenv/bin/python3 # -*- coding: utf-8 -*- import re import sys diff --git a/myvenv/bin/pip3.10 b/myvenv/bin/pip3.10 index f942e440..bde8aded 100755 --- a/myvenv/bin/pip3.10 +++ b/myvenv/bin/pip3.10 @@ -1,4 +1,4 @@ -#!/Users/ahyeonlim/YUSEO-Server/myvenv/bin/python3 +#!/Users/ahyeonlim/Otr-Server/myvenv/bin/python3 # -*- coding: utf-8 -*- import re import sys diff --git a/myvenv/bin/sqlformat b/myvenv/bin/sqlformat index 2eb4ec67..67bd5f17 100755 --- a/myvenv/bin/sqlformat +++ b/myvenv/bin/sqlformat @@ -1,4 +1,4 @@ -#!/Users/ahyeonlim/YUSEO-Server/myvenv/bin/python3 +#!/Users/ahyeonlim/Otr-Server/myvenv/bin/python3 # -*- coding: utf-8 -*- import re import sys diff --git a/yuseo/yuseo/settings.py b/yuseo/yuseo/settings.py index 04570784..25021fd1 100644 --- a/yuseo/yuseo/settings.py +++ b/yuseo/yuseo/settings.py @@ -10,6 +10,7 @@ https://docs.djangoproject.com/en/4.0/ref/settings/ """ +import os from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -124,3 +125,7 @@ # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + + +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') +MEDIA_URL = '/media/' \ No newline at end of file diff --git a/yuseo/yuseo/urls.py b/yuseo/yuseo/urls.py index e33796ac..16a975bc 100644 --- a/yuseo/yuseo/urls.py +++ b/yuseo/yuseo/urls.py @@ -15,8 +15,10 @@ """ from django.contrib import admin from django.urls import path, include +from django.conf import settings +from django.conf.urls.static import static urlpatterns = [ path('admin/', admin.site.urls), path('', include('yuseoapp.urls')) -] +]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/yuseo/yuseoapp/migrations/0001_initial.py b/yuseo/yuseoapp/migrations/0001_initial.py index 2c1b8581..5d89110f 100644 --- a/yuseo/yuseoapp/migrations/0001_initial.py +++ b/yuseo/yuseoapp/migrations/0001_initial.py @@ -18,6 +18,7 @@ class Migration(migrations.Migration): ('title', models.CharField(max_length=100)), ('date', models.DateTimeField(auto_now_add=True)), ('body', models.TextField()), + ('image', models.ImageField(upload_to="%Y/%m/%d")), ], ), ] diff --git a/yuseo/yuseoapp/migrations/0002_alter_yuseo_image.py b/yuseo/yuseoapp/migrations/0002_alter_yuseo_image.py new file mode 100644 index 00000000..d94e5d55 --- /dev/null +++ b/yuseo/yuseoapp/migrations/0002_alter_yuseo_image.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.6 on 2022-08-03 14:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('yuseoapp', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='yuseo', + name='image', + field=models.ImageField(null=True, upload_to='%Y/%m/%d'), + ), + ] diff --git a/yuseo/yuseoapp/models.py b/yuseo/yuseoapp/models.py index b9332985..4cbb531c 100644 --- a/yuseo/yuseoapp/models.py +++ b/yuseo/yuseoapp/models.py @@ -7,11 +7,13 @@ class Yuseo(models.Model): title = models.CharField(max_length=100) date = models.DateTimeField(auto_now_add=True) body = models.TextField() + image = models.ImageField(upload_to='%Y/%m/%d', null=True) + def __Str__(self): return self.title def summary(self): return self.body [:30] - - \ No newline at end of file + + diff --git a/yuseo/yuseoapp/serializers.py b/yuseo/yuseoapp/serializers.py index b67b73f2..29032b5f 100644 --- a/yuseo/yuseoapp/serializers.py +++ b/yuseo/yuseoapp/serializers.py @@ -1,15 +1,45 @@ -from dataclasses import field +from asyncio import Task +from dataclasses import field, fields from rest_framework import serializers -from .models import Yuseo +from .models import Yuseo + + + + class YuseoSerializer(serializers.ModelSerializer): + image = serializers.ImageField(use_url=True) + class Meta: model = Yuseo - fields = ('id', 'title', 'date', 'body') + fields = ('id', 'title', 'date', 'body', 'image') class YuseoListSerializer(serializers.ModelSerializer): class Meta: model = Yuseo fields = ('id', 'title', 'date', 'summary') - \ No newline at end of file + + + +"""class TaskImageSerializer(serializers.ModelSerializer): + class Meta: + model = TaskImage + fields = ('image',) + + +class TaskSerializer(serializers.HyperlinkedModelSerializer): + user = serializers.ReadOnlyField(source='user.username') + images = TaskImageSerializer(source='taskimage_set', many=True, read_only=True) + + class Meta: + model = Task + fields = ('id', 'title', 'date', 'body', 'images') + + def create(self, validated_data): + images_data = self.context.get('view').request.FILES + task = Task.objects.create(title=validated_data.get('title', 'no-title'), + user_id=1) + for image_data in images_data.values(): + TaskImage.objects.create(task=task, image=image_data) + return task""" \ No newline at end of file