added application gallery

This commit is contained in:
Anatoly 2019-08-27 13:02:54 +03:00
parent 5edcd0afe9
commit 15c1950184
9 changed files with 73 additions and 0 deletions

0
apps/gallery/__init__.py Normal file
View File

8
apps/gallery/admin.py Normal file
View File

@ -0,0 +1,8 @@
from django.contrib import admin
from gallery.models import Gallery
@admin.register(Gallery)
class GalleryModelAdmin(admin.ModelAdmin):
"""Gallery model admin"""

7
apps/gallery/apps.py Normal file
View File

@ -0,0 +1,7 @@
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _
class GalleryConfig(AppConfig):
name = 'gallery'
verbose_name = _('gallery')

View File

16
apps/gallery/models.py Normal file
View File

@ -0,0 +1,16 @@
from django.utils.translation import gettext_lazy as _
from utils.models import ProjectBaseMixin, ImageMixin
class Gallery(ProjectBaseMixin, ImageMixin):
"""Gallery model."""
class Meta:
"""Meta class."""
verbose_name = _('Gallery')
verbose_name_plural = _('Galleries')
def __str__(self):
"""String representation"""
return str(self.get_image_url)

View File

@ -0,0 +1,20 @@
from rest_framework import serializers
from . import models
class GallerySerializer(serializers.ModelSerializer):
"""Serializer for model Gallery."""
# RESPONSE
url = serializers.URLField(source='get_image_url')
class Meta:
"""Meta class"""
model = models.Gallery
fields = (
'image',
'url'
)
read_only_fields = (
'url',
)

1
apps/gallery/tests.py Normal file
View File

@ -0,0 +1 @@
# Create your tests here.

11
apps/gallery/urls.py Normal file
View File

@ -0,0 +1,11 @@
"""Gallery urlpaths."""
from django.urls import path
from . import views
app_name = 'gallery'
url_patterns = [
path('upload/', views.GalleryUploadImage.as_view(),
name='upload_image')
]

10
apps/gallery/views.py Normal file
View File

@ -0,0 +1,10 @@
from rest_framework import generics
from . import models, serializers
class GalleryUploadImage(generics.CreateAPIView):
"""Upload image to gallery"""
model = models.Gallery
queryset = models.Gallery.objects.all()
serializer_class = serializers.GallerySerializer