From c5f5c6d74a48aafd62502780184ff69d8b82fd7a Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Wed, 16 Mar 2022 10:12:02 -0500 Subject: [PATCH 1/5] saving shell files --- smugfolioapi/views/image_tag_assignments.py | 0 smugfolioapi/views/image_tags.py | 0 smugfolioapi/views/images.py | 0 smugfolioapi/views/smug_users.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 smugfolioapi/views/image_tag_assignments.py create mode 100644 smugfolioapi/views/image_tags.py create mode 100644 smugfolioapi/views/images.py create mode 100644 smugfolioapi/views/smug_users.py diff --git a/smugfolioapi/views/image_tag_assignments.py b/smugfolioapi/views/image_tag_assignments.py new file mode 100644 index 0000000..e69de29 diff --git a/smugfolioapi/views/image_tags.py b/smugfolioapi/views/image_tags.py new file mode 100644 index 0000000..e69de29 diff --git a/smugfolioapi/views/images.py b/smugfolioapi/views/images.py new file mode 100644 index 0000000..e69de29 diff --git a/smugfolioapi/views/smug_users.py b/smugfolioapi/views/smug_users.py new file mode 100644 index 0000000..e69de29 -- 2.47.3 From c3a389de28c291f9bf30dbd6e85b4e9bceb36b1a Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Wed, 16 Mar 2022 14:16:16 -0500 Subject: [PATCH 2/5] saving completed image view for API --- smugfolioapi/models/images.py | 2 +- smugfolioapi/views/__init__.py | 3 +- smugfolioapi/views/image_tag_assignments.py | 0 smugfolioapi/views/images.py | 98 +++++++++++++++++++++ smugfolioserver/db.sql | 4 +- smugfolioserver/urls.py | 8 +- 6 files changed, 110 insertions(+), 5 deletions(-) delete mode 100644 smugfolioapi/views/image_tag_assignments.py diff --git a/smugfolioapi/models/images.py b/smugfolioapi/models/images.py index 0aa21a4..3c6498f 100644 --- a/smugfolioapi/models/images.py +++ b/smugfolioapi/models/images.py @@ -4,7 +4,7 @@ class Images(models.Model): file_name = models.CharField(max_length=1024) file_path = models.CharField(max_length=1024) album_id = models.IntegerField(default=0) - smug_user_id = models.ForeignKey("Smug_Users", on_delete=models.CASCADE) + smug_user = models.ForeignKey("Smug_Users", on_delete=models.CASCADE) upload_date = models.DateTimeField(auto_now_add=True) # I believe that auto_now_add is the correct syntax. If I'm understanding this correctly, it only creates a timestamp when the object is first created. diff --git a/smugfolioapi/views/__init__.py b/smugfolioapi/views/__init__.py index 0801135..f769e06 100644 --- a/smugfolioapi/views/__init__.py +++ b/smugfolioapi/views/__init__.py @@ -1 +1,2 @@ -from .auth import login_user, register_user \ No newline at end of file +from .auth import login_user, register_user +from .images import ImageView \ No newline at end of file diff --git a/smugfolioapi/views/image_tag_assignments.py b/smugfolioapi/views/image_tag_assignments.py deleted file mode 100644 index e69de29..0000000 diff --git a/smugfolioapi/views/images.py b/smugfolioapi/views/images.py index e69de29..a001d8c 100644 --- a/smugfolioapi/views/images.py +++ b/smugfolioapi/views/images.py @@ -0,0 +1,98 @@ +from django.http import HttpResponseServerError +from rest_framework.viewsets import ViewSet +from rest_framework.response import Response +from rest_framework import serializers, status +from smugfolioapi.models import Images, Smug_Users + +class ImageView(ViewSet): + """SmugFolio images s view""" + + def retrieve(self, request, pk): + """Handle GET requests for single images + + + Returns: + Response -- JSON serialized images + """ + + + + try: + images = Images.objects.get(pk=pk) + serializer = ImagesSerializer(images) + return Response(serializer.data) + except Images.DoesNotExist as ex: + return Response({'message': ex.args[0]}, status=status.HTTP_404_NOT_FOUND) + + + def list(self, request): + """Handle GET requests to get all images + + Returns: + Response -- JSON serialized list of images + """ + images_ = request.query_params.get('type', None) + images = Images.objects.all() + if images_ is not None: + images = images.filter(images_type_id=images_) + serializer = ImagesSerializer(images, many=True) + return Response(serializer.data) + + def create(self, request): + """Handle POST operations + + Returns + Response -- JSON serialized images instance + """ + # object must be retrived when using a foreign key + smug_user = Smug_Users.objects.get(pk=request.data['smug_user']) + images = Images.objects.create( + file_name=request.data["file_name"], + file_path=request.data["file_path"], + album_id=request.data["album_id"], + smug_user=smug_user, + upload_date = request.data["upload_date"] + ) + serializer = ImagesSerializer(images) + return Response(serializer.data, status=201) + + def update(self, request, pk): + """Handle PUT requests for a images + + Returns: + Response -- Empty body with 204 status code + """ + # Refactor keys to match ERD + images = Images.objects.get(pk=pk) + images.file_name = request.data["file_name"] + images.file_path = request.data["file_path"] + images.album_id = request.data["album_id"] + images.smug_user_id = request.data["skill_level"] + images.upload_date = request.data["upload_date"] + + return Response(None, status=status.HTTP_204_NO_CONTENT) + def destroy(self, request, pk): + """Handle DELETE requests for a images + + Args: + request (object): DELETE request object + pk (num): Accepts the argument of the primary key of a images + + Returns: + Status: If the method completes successfully, return a HTTP response 204 + """ + images = Images.objects.get(pk=pk) + images.delete() + return Response(None, status=status.HTTP_204_NO_CONTENT) + + +class ImagesSerializer(serializers.ModelSerializer): + """JSON serializer for images s + """ + class Meta: + model = Images + fields = ('id', 'file_name', 'file_path', 'album_id', 'smug_user_id', 'upload_date') + depth = 2 + + + \ No newline at end of file diff --git a/smugfolioserver/db.sql b/smugfolioserver/db.sql index 3502d83..0e49153 100644 --- a/smugfolioserver/db.sql +++ b/smugfolioserver/db.sql @@ -1,2 +1,2 @@ -DELETE FROM 'auth_user' -WHERE id=2; \ No newline at end of file +ALTER TABLE smugfolioapi_images +RENAME 'smug_user_id_id' TO 'smug_user_id'; \ No newline at end of file diff --git a/smugfolioserver/urls.py b/smugfolioserver/urls.py index dc3dd48..37a1f70 100644 --- a/smugfolioserver/urls.py +++ b/smugfolioserver/urls.py @@ -16,12 +16,18 @@ Including another URLconf from django.contrib import admin from django.conf.urls import include from django.urls import path -from smugfolioapi.views import register_user, login_user +from smugfolioapi.models.smug_users import Smug_Users +from smugfolioapi.views import register_user, login_user, ImageView from rest_framework import routers from django.contrib import admin from django.urls import path +from smugfolioapi.views.images import ImageView + router = routers.DefaultRouter(trailing_slash=False) +router.register(r'images', ImageView, 'image') +# router.register(r'smug_users',Smug_Users,'smug_user') +# router.register(r'image_tags', Image_Tags,'image_tag') urlpatterns = [ path('admin/', admin.site.urls), -- 2.47.3 From ff6891dd7002de3436514e76c57cb94cf1f52f70 Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Thu, 17 Mar 2022 09:49:53 -0500 Subject: [PATCH 3/5] saving completed views --- smugfolioapi/models/images.py | 4 ++ smugfolioapi/views/__init__.py | 4 +- smugfolioapi/views/image_tags.py | 91 ++++++++++++++++++++++++++++++ smugfolioapi/views/images.py | 1 + smugfolioapi/views/smug_users.py | 97 ++++++++++++++++++++++++++++++++ smugfolioserver/urls.py | 9 ++- 6 files changed, 200 insertions(+), 6 deletions(-) diff --git a/smugfolioapi/models/images.py b/smugfolioapi/models/images.py index 3c6498f..6fe28a9 100644 --- a/smugfolioapi/models/images.py +++ b/smugfolioapi/models/images.py @@ -7,5 +7,9 @@ class Images(models.Model): smug_user = models.ForeignKey("Smug_Users", on_delete=models.CASCADE) upload_date = models.DateTimeField(auto_now_add=True) + @property + def imagecount(self): + return self.__imagecount + # I believe that auto_now_add is the correct syntax. If I'm understanding this correctly, it only creates a timestamp when the object is first created. # https://www.geeksforgeeks.org/datetimefield-django-models/ \ No newline at end of file diff --git a/smugfolioapi/views/__init__.py b/smugfolioapi/views/__init__.py index f769e06..a113543 100644 --- a/smugfolioapi/views/__init__.py +++ b/smugfolioapi/views/__init__.py @@ -1,2 +1,4 @@ from .auth import login_user, register_user -from .images import ImageView \ No newline at end of file +from .images import ImageView +from .smug_users import SmugUserView +from .image_tags import Image_Tags \ No newline at end of file diff --git a/smugfolioapi/views/image_tags.py b/smugfolioapi/views/image_tags.py index e69de29..ad4c21e 100644 --- a/smugfolioapi/views/image_tags.py +++ b/smugfolioapi/views/image_tags.py @@ -0,0 +1,91 @@ +from django.http import HttpResponseServerError +from rest_framework.viewsets import ViewSet +from rest_framework.response import Response +from rest_framework import serializers, status +from django.contrib.auth.models import User +from smugfolioapi.models import Image_Tags + +class ImageTagsView(ViewSet): + """SmugFolio image_Tags s view""" + + def retrieve(self, request, pk): + """Handle GET requests for single image_Tags + + + Returns: + Response -- JSON serialized image_Tags + """ + + + + try: + image_Tags = Image_Tags.objects.get(pk=pk) + serializer = Image_TagsSerializer(image_Tags) + return Response(serializer.data) + except Image_Tags.DoesNotExist as ex: + return Response({'message': ex.args[0]}, status=status.HTTP_404_NOT_FOUND) + + + def list(self, request): + """Handle GET requests to get all image_Tags + + Returns: + Response -- JSON serialized list of image_Tags + """ + image_Tags_ = request.query_params.get('type', None) + image_Tags = Image_Tags.objects.all() + if image_Tags_ is not None: + image_Tags = image_Tags.filter(image_Tags_type_id=image_Tags_) + serializer = Image_TagsSerializer(image_Tags, many=True) + return Response(serializer.data) + + def create(self, request): + """Handle POST operations + + Returns + Response -- JSON serialized image_Tags instance + """ + image_Tags = image_Tags.objects.create( + image_tag_name = request.data["image_tag_name"] + + ) + serializer = Image_TagsSerializer(image_Tags) + return Response(serializer.data, status=201) + + def update(self, request, pk): + """Handle PUT requests for a image_Tags + + Returns: + Response -- Empty body with 204 status code + """ + + image_Tags = Image_Tags.objects.get(pk=request.data['id']) + image_Tags.image_tag_name = request.data["image_tag_name"] + + + return Response(None, status=status.HTTP_204_NO_CONTENT) + def destroy(self, request, pk): + """Handle DELETE requests for a image_Tags + + Args: + request (object): DELETE request object + pk (num): Accepts the argument of the primary key of a image_Tags + + Returns: + Status: If the method completes successfully, return a HTTP response 204 + """ + image_Tags = image_Tags.objects.get(pk=pk) + image_Tags.delete() + return Response(None, status=status.HTTP_204_NO_CONTENT) + + +class Image_TagsSerializer(serializers.ModelSerializer): + """JSON serializer for image_Tags s + """ + class Meta: + model = Image_Tags + fields = ('id', 'image_tag_name') + depth = 2 + + + \ No newline at end of file diff --git a/smugfolioapi/views/images.py b/smugfolioapi/views/images.py index a001d8c..0f126ab 100644 --- a/smugfolioapi/views/images.py +++ b/smugfolioapi/views/images.py @@ -3,6 +3,7 @@ from rest_framework.viewsets import ViewSet from rest_framework.response import Response from rest_framework import serializers, status from smugfolioapi.models import Images, Smug_Users +from PIL import Image class ImageView(ViewSet): """SmugFolio images s view""" diff --git a/smugfolioapi/views/smug_users.py b/smugfolioapi/views/smug_users.py index e69de29..3d58b31 100644 --- a/smugfolioapi/views/smug_users.py +++ b/smugfolioapi/views/smug_users.py @@ -0,0 +1,97 @@ +from django.http import HttpResponseServerError +from rest_framework.viewsets import ViewSet +from rest_framework.response import Response +from rest_framework import serializers, status +from django.contrib.auth.models import User +from smugfolioapi.models import Smug_Users + +class SmugUserView(ViewSet): + """SmugFolio smug_users s view""" + + def retrieve(self, request, pk): + """Handle GET requests for single smug_users + + + Returns: + Response -- JSON serialized smug_users + """ + + + + try: + smug_users = Smug_Users.objects.get(pk=pk) + serializer = Smug_UsersSerializer(smug_users) + return Response(serializer.data) + except Smug_Users.DoesNotExist as ex: + return Response({'message': ex.args[0]}, status=status.HTTP_404_NOT_FOUND) + + + def list(self, request): + """Handle GET requests to get all smug_users + + Returns: + Response -- JSON serialized list of smug_users + """ + smug_users_ = request.query_params.get('type', None) + smug_users = Smug_Users.objects.all() + if smug_users_ is not None: + smug_users = smug_users.filter(smug_users_type_id=smug_users_) + serializer = Smug_UsersSerializer(smug_users, many=True) + return Response(serializer.data) + + def create(self, request): + """Handle POST operations + + Returns + Response -- JSON serialized smug_users instance + """ + # object must be retrived when using a foreign key + user = User.objects.get(pk=request.data['users']) + smug_users = smug_users.objects.create( + user=request.data["user"], + business_name=request.data["business_name"], + business_owner=request.data["business_owner"], + + ) + serializer = Smug_UsersSerializer(smug_users) + return Response(serializer.data, status=201) + + def update(self, request, pk): + """Handle PUT requests for a smug_users + + Returns: + Response -- Empty body with 204 status code + """ + + smug_users = smug_users.objects.get(pk=pk) + smug_users.user = request.data["user"] + smug_users.business_name = request.data["business_name"] + smug_users.business_owner = request.data["business_owner"] + + + return Response(None, status=status.HTTP_204_NO_CONTENT) + def destroy(self, request, pk): + """Handle DELETE requests for a smug_users + + Args: + request (object): DELETE request object + pk (num): Accepts the argument of the primary key of a smug_users + + Returns: + Status: If the method completes successfully, return a HTTP response 204 + """ + smug_users = smug_users.objects.get(pk=pk) + smug_users.delete() + return Response(None, status=status.HTTP_204_NO_CONTENT) + + +class Smug_UsersSerializer(serializers.ModelSerializer): + """JSON serializer for smug_users s + """ + class Meta: + model = Smug_Users + fields = ('id', 'business_name', 'business_owner') + depth = 2 + + + \ No newline at end of file diff --git a/smugfolioserver/urls.py b/smugfolioserver/urls.py index 37a1f70..e9bb197 100644 --- a/smugfolioserver/urls.py +++ b/smugfolioserver/urls.py @@ -16,18 +16,17 @@ Including another URLconf from django.contrib import admin from django.conf.urls import include from django.urls import path -from smugfolioapi.models.smug_users import Smug_Users -from smugfolioapi.views import register_user, login_user, ImageView +from smugfolioapi.views import register_user, login_user, ImageView, SmugUserView from rest_framework import routers from django.contrib import admin from django.urls import path - +from smugfolioapi.views.image_tags import ImageTagsView from smugfolioapi.views.images import ImageView router = routers.DefaultRouter(trailing_slash=False) router.register(r'images', ImageView, 'image') -# router.register(r'smug_users',Smug_Users,'smug_user') -# router.register(r'image_tags', Image_Tags,'image_tag') +router.register(r'smug_users',SmugUserView,'smug_user') +router.register(r'image_tags', ImageTagsView,'image_tag') urlpatterns = [ path('admin/', admin.site.urls), -- 2.47.3 From 3cbb666213b61ec7245efebfd1b1809d179a4308 Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Thu, 17 Mar 2022 13:09:02 -0500 Subject: [PATCH 4/5] saving completed page views --- smugfolioapi/views/image_tags.py | 11 ++++++----- smugfolioapi/views/images.py | 7 ++++--- smugfolioapi/views/smug_users.py | 17 ----------------- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/smugfolioapi/views/image_tags.py b/smugfolioapi/views/image_tags.py index ad4c21e..4193189 100644 --- a/smugfolioapi/views/image_tags.py +++ b/smugfolioapi/views/image_tags.py @@ -45,7 +45,8 @@ class ImageTagsView(ViewSet): Returns Response -- JSON serialized image_Tags instance """ - image_Tags = image_Tags.objects.create( + + image_Tags = Image_Tags.objects.create( image_tag_name = request.data["image_tag_name"] ) @@ -59,9 +60,9 @@ class ImageTagsView(ViewSet): Response -- Empty body with 204 status code """ - image_Tags = Image_Tags.objects.get(pk=request.data['id']) + image_Tags = Image_Tags.objects.get(pk=pk) image_Tags.image_tag_name = request.data["image_tag_name"] - + image_Tags.save() return Response(None, status=status.HTTP_204_NO_CONTENT) def destroy(self, request, pk): @@ -69,12 +70,12 @@ class ImageTagsView(ViewSet): Args: request (object): DELETE request object - pk (num): Accepts the argument of the primary key of a image_Tags + pk (num): Accepts the argument of the primary key of an image_Tags Returns: Status: If the method completes successfully, return a HTTP response 204 """ - image_Tags = image_Tags.objects.get(pk=pk) + image_Tags = Image_Tags.objects.get(pk=pk) image_Tags.delete() return Response(None, status=status.HTTP_204_NO_CONTENT) diff --git a/smugfolioapi/views/images.py b/smugfolioapi/views/images.py index 0f126ab..4935ccd 100644 --- a/smugfolioapi/views/images.py +++ b/smugfolioapi/views/images.py @@ -46,7 +46,7 @@ class ImageView(ViewSet): Response -- JSON serialized images instance """ # object must be retrived when using a foreign key - smug_user = Smug_Users.objects.get(pk=request.data['smug_user']) + smug_user = Smug_Users.objects.get(user=request.auth.user) images = Images.objects.create( file_name=request.data["file_name"], file_path=request.data["file_path"], @@ -68,8 +68,9 @@ class ImageView(ViewSet): images.file_name = request.data["file_name"] images.file_path = request.data["file_path"] images.album_id = request.data["album_id"] - images.smug_user_id = request.data["skill_level"] - images.upload_date = request.data["upload_date"] + images.smug_user_id = request.data["smug_user_id"] + images.upload_date = request.data["upload_date"] + images.save() return Response(None, status=status.HTTP_204_NO_CONTENT) def destroy(self, request, pk): diff --git a/smugfolioapi/views/smug_users.py b/smugfolioapi/views/smug_users.py index 3d58b31..bb8c228 100644 --- a/smugfolioapi/views/smug_users.py +++ b/smugfolioapi/views/smug_users.py @@ -38,23 +38,6 @@ class SmugUserView(ViewSet): smug_users = smug_users.filter(smug_users_type_id=smug_users_) serializer = Smug_UsersSerializer(smug_users, many=True) return Response(serializer.data) - - def create(self, request): - """Handle POST operations - - Returns - Response -- JSON serialized smug_users instance - """ - # object must be retrived when using a foreign key - user = User.objects.get(pk=request.data['users']) - smug_users = smug_users.objects.create( - user=request.data["user"], - business_name=request.data["business_name"], - business_owner=request.data["business_owner"], - - ) - serializer = Smug_UsersSerializer(smug_users) - return Response(serializer.data, status=201) def update(self, request, pk): """Handle PUT requests for a smug_users -- 2.47.3 From 14a98f65ed31e8076f337f06d819e971a1ed2263 Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Thu, 17 Mar 2022 15:56:28 -0500 Subject: [PATCH 5/5] Added all views that can be tested without a client --- db.sql | 0 ...user_id_images_smug_user_images_picture.py | 23 +++++++++++++++++++ smugfolioapi/models/images.py | 15 ++++++++---- smugfolioapi/views/image_tags.py | 1 + smugfolioapi/views/images.py | 13 ++++++++--- smugfolioserver/__init__.py | 1 + smugfolioserver/db.sql | 7 ++++-- smugfolioserver/settings.py | 5 +++- smugfolioserver/urls.py | 4 +++- 9 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 db.sql create mode 100644 smugfolioapi/migrations/0002_rename_smug_user_id_images_smug_user_images_picture.py diff --git a/db.sql b/db.sql new file mode 100644 index 0000000..e69de29 diff --git a/smugfolioapi/migrations/0002_rename_smug_user_id_images_smug_user_images_picture.py b/smugfolioapi/migrations/0002_rename_smug_user_id_images_smug_user_images_picture.py new file mode 100644 index 0000000..52298e7 --- /dev/null +++ b/smugfolioapi/migrations/0002_rename_smug_user_id_images_smug_user_images_picture.py @@ -0,0 +1,23 @@ +# Generated by Django 4.0.3 on 2022-03-17 18:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('smugfolioapi', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='images', + old_name='smug_user_id', + new_name='smug_user', + ), + migrations.AddField( + model_name='images', + name='picture', + field=models.ImageField(null=True, upload_to='smugimages'), + ), + ] diff --git a/smugfolioapi/models/images.py b/smugfolioapi/models/images.py index 6fe28a9..1a5ff0f 100644 --- a/smugfolioapi/models/images.py +++ b/smugfolioapi/models/images.py @@ -1,15 +1,20 @@ from django.db import models class Images(models.Model): - file_name = models.CharField(max_length=1024) - file_path = models.CharField(max_length=1024) album_id = models.IntegerField(default=0) smug_user = models.ForeignKey("Smug_Users", on_delete=models.CASCADE) upload_date = models.DateTimeField(auto_now_add=True) + picture = models.ImageField( + upload_to='smugimages', height_field=None, + width_field=None, max_length=None, null=True + ) - @property - def imagecount(self): - return self.__imagecount + # @property + # def imagecount(self): + # return self.__imagecount + # @imagecount.setter + # def imagecount(self, value): + # self.__imagecount = value # I believe that auto_now_add is the correct syntax. If I'm understanding this correctly, it only creates a timestamp when the object is first created. # https://www.geeksforgeeks.org/datetimefield-django-models/ \ No newline at end of file diff --git a/smugfolioapi/views/image_tags.py b/smugfolioapi/views/image_tags.py index 4193189..ce42c53 100644 --- a/smugfolioapi/views/image_tags.py +++ b/smugfolioapi/views/image_tags.py @@ -4,6 +4,7 @@ from rest_framework.response import Response from rest_framework import serializers, status from django.contrib.auth.models import User from smugfolioapi.models import Image_Tags +from rest_framework.decorators import action class ImageTagsView(ViewSet): """SmugFolio image_Tags s view""" diff --git a/smugfolioapi/views/images.py b/smugfolioapi/views/images.py index 4935ccd..930db10 100644 --- a/smugfolioapi/views/images.py +++ b/smugfolioapi/views/images.py @@ -4,6 +4,9 @@ from rest_framework.response import Response from rest_framework import serializers, status from smugfolioapi.models import Images, Smug_Users from PIL import Image +import uuid +import base64 +from django.core.files.base import ContentFile class ImageView(ViewSet): """SmugFolio images s view""" @@ -35,7 +38,7 @@ class ImageView(ViewSet): images_ = request.query_params.get('type', None) images = Images.objects.all() if images_ is not None: - images = images.filter(images_type_id=images_) + images = images.filter(images_type_id=images_) serializer = ImagesSerializer(images, many=True) return Response(serializer.data) @@ -46,12 +49,16 @@ class ImageView(ViewSet): Response -- JSON serialized images instance """ # object must be retrived when using a foreign key + format, imgstr = request.data["picture"].split(';base64,') + ext = format.split('/')[-1] + data = ContentFile(base64.b64decode(imgstr), name=f'{request.data["picture"]}-{uuid.uuid4()}.{ext}') smug_user = Smug_Users.objects.get(user=request.auth.user) images = Images.objects.create( file_name=request.data["file_name"], file_path=request.data["file_path"], album_id=request.data["album_id"], - smug_user=smug_user, + picture= data, + smug_user= smug_user, upload_date = request.data["upload_date"] ) serializer = ImagesSerializer(images) @@ -93,7 +100,7 @@ class ImagesSerializer(serializers.ModelSerializer): """ class Meta: model = Images - fields = ('id', 'file_name', 'file_path', 'album_id', 'smug_user_id', 'upload_date') + fields = ('id', 'file_name', 'file_path', 'album_id', 'smug_user_id', 'upload_date', 'picture', 'imagecount') depth = 2 diff --git a/smugfolioserver/__init__.py b/smugfolioserver/__init__.py index e69de29..3f0901b 100644 --- a/smugfolioserver/__init__.py +++ b/smugfolioserver/__init__.py @@ -0,0 +1 @@ +from .settings import MEDIA_URL, MEDIA_ROOT \ No newline at end of file diff --git a/smugfolioserver/db.sql b/smugfolioserver/db.sql index 0e49153..6517769 100644 --- a/smugfolioserver/db.sql +++ b/smugfolioserver/db.sql @@ -1,2 +1,5 @@ -ALTER TABLE smugfolioapi_images -RENAME 'smug_user_id_id' TO 'smug_user_id'; \ No newline at end of file +DELETE FROM smugfolioapi_images +WHERE id = 1; + +SELECT * +FROM smugfolioapi_images; \ No newline at end of file diff --git a/smugfolioserver/settings.py b/smugfolioserver/settings.py index 453d1b6..db8d1b8 100644 --- a/smugfolioserver/settings.py +++ b/smugfolioserver/settings.py @@ -148,4 +148,7 @@ STATIC_URL = 'static/' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' -SECRET_KEY = os.environ.get('MY_SECRET_KEY') \ No newline at end of file +SECRET_KEY = os.environ.get('MY_SECRET_KEY') + +MEDIA_ROOT = 'media' +MEDIA_URL = '/media/' \ No newline at end of file diff --git a/smugfolioserver/urls.py b/smugfolioserver/urls.py index e9bb197..2675cba 100644 --- a/smugfolioserver/urls.py +++ b/smugfolioserver/urls.py @@ -20,8 +20,10 @@ from smugfolioapi.views import register_user, login_user, ImageView, SmugUserVie from rest_framework import routers from django.contrib import admin from django.urls import path +from django.conf.urls.static import static from smugfolioapi.views.image_tags import ImageTagsView from smugfolioapi.views.images import ImageView +from smugfolioserver import settings, MEDIA_ROOT, MEDIA_URL router = routers.DefaultRouter(trailing_slash=False) router.register(r'images', ImageView, 'image') @@ -34,4 +36,4 @@ urlpatterns = [ path('login', login_user), path('api-auth', include('rest_framework.urls', namespace='rest_framework')), path('', include(router.urls)), -] +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) -- 2.47.3