refactored gallery app
This commit is contained in:
parent
ce260a69aa
commit
2172972216
17
apps/collection/migrations/0006_remove_collection_image.py
Normal file
17
apps/collection/migrations/0006_remove_collection_image.py
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-08-27 15:34
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('collection', '0005_auto_20190823_1401'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='collection',
|
||||||
|
name='image',
|
||||||
|
),
|
||||||
|
]
|
||||||
20
apps/collection/migrations/0007_collection_image.py
Normal file
20
apps/collection/migrations/0007_collection_image.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-08-27 15:42
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('gallery', '0001_initial'),
|
||||||
|
('collection', '0006_remove_collection_image'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='collection',
|
||||||
|
name='image',
|
||||||
|
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='gallery.Image', verbose_name='Collection image'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -38,9 +38,11 @@ class CollectionQuerySet(models.QuerySet):
|
||||||
return self.filter(is_publish=True)
|
return self.filter(is_publish=True)
|
||||||
|
|
||||||
|
|
||||||
class Collection(ProjectBaseMixin, CollectionNameMixin,
|
class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin):
|
||||||
ImageMixin, CollectionDateMixin):
|
|
||||||
"""Collection model."""
|
"""Collection model."""
|
||||||
|
image = models.ForeignKey(
|
||||||
|
'gallery.Image', null=True, blank=True, default=None,
|
||||||
|
verbose_name=_('Collection image'), on_delete=models.CASCADE)
|
||||||
is_publish = models.BooleanField(
|
is_publish = models.BooleanField(
|
||||||
default=False, verbose_name=_('Publish status'))
|
default=False, verbose_name=_('Publish status'))
|
||||||
on_top = models.BooleanField(
|
on_top = models.BooleanField(
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ from collection import models
|
||||||
|
|
||||||
class CollectionSerializer(serializers.ModelSerializer):
|
class CollectionSerializer(serializers.ModelSerializer):
|
||||||
"""Collection serializer"""
|
"""Collection serializer"""
|
||||||
|
image = serializers.URLField(source='image.get_image_url')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Collection
|
model = models.Collection
|
||||||
fields = [
|
fields = [
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from gallery.models import Gallery
|
from gallery.models import Image
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Gallery)
|
@admin.register(Image)
|
||||||
class GalleryModelAdmin(admin.ModelAdmin):
|
class ImageModelAdmin(admin.ModelAdmin):
|
||||||
"""Gallery model admin"""
|
"""Image model admin"""
|
||||||
|
|
|
||||||
30
apps/gallery/migrations/0001_initial.py
Normal file
30
apps/gallery/migrations/0001_initial.py
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-08-27 15:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.utils.timezone
|
||||||
|
import easy_thumbnails.fields
|
||||||
|
import utils.methods
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Image',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('created', models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='Date created')),
|
||||||
|
('modified', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||||
|
('image', easy_thumbnails.fields.ThumbnailerImageField(upload_to=utils.methods.image_path, verbose_name='Image file')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Image',
|
||||||
|
'verbose_name_plural': 'Images',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -1,16 +1,21 @@
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from easy_thumbnails.fields import ThumbnailerImageField
|
||||||
|
|
||||||
|
from utils.methods import image_path
|
||||||
from utils.models import ProjectBaseMixin, ImageMixin
|
from utils.models import ProjectBaseMixin, ImageMixin
|
||||||
|
|
||||||
|
|
||||||
class Gallery(ProjectBaseMixin, ImageMixin):
|
class Image(ProjectBaseMixin, ImageMixin):
|
||||||
"""Gallery model."""
|
"""Image model."""
|
||||||
|
|
||||||
|
image = ThumbnailerImageField(upload_to=image_path,
|
||||||
|
verbose_name=_('Image file'))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
verbose_name = _('Gallery')
|
verbose_name = _('Image')
|
||||||
verbose_name_plural = _('Galleries')
|
verbose_name_plural = _('Images')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""String representation"""
|
"""String representation"""
|
||||||
return str(self.get_image_url)
|
return str(self.id)
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,15 @@ from rest_framework import serializers
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
|
||||||
class GallerySerializer(serializers.ModelSerializer):
|
class ImageSerializer(serializers.ModelSerializer):
|
||||||
"""Serializer for model Gallery."""
|
"""Serializer for model Image."""
|
||||||
# RESPONSE
|
# RESPONSE
|
||||||
url = serializers.URLField(source='get_image_url')
|
url = serializers.URLField(source='get_image_url',
|
||||||
|
required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class"""
|
"""Meta class"""
|
||||||
model = models.Gallery
|
model = models.Image
|
||||||
fields = (
|
fields = (
|
||||||
'image',
|
'image',
|
||||||
'url'
|
'url'
|
||||||
|
|
|
||||||
17
apps/news/migrations/0006_remove_news_image.py
Normal file
17
apps/news/migrations/0006_remove_news_image.py
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-08-27 15:33
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('news', '0005_auto_20190823_1149'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='news',
|
||||||
|
name='image',
|
||||||
|
),
|
||||||
|
]
|
||||||
20
apps/news/migrations/0007_news_image.py
Normal file
20
apps/news/migrations/0007_news_image.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-08-27 15:42
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('gallery', '0001_initial'),
|
||||||
|
('news', '0006_remove_news_image'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='news',
|
||||||
|
name='image',
|
||||||
|
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='gallery.Image', verbose_name='News image'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -37,8 +37,11 @@ class NewsQuerySet(models.QuerySet):
|
||||||
return self.filter(is_publish=True)
|
return self.filter(is_publish=True)
|
||||||
|
|
||||||
|
|
||||||
class News(ImageMixin, BaseAttributes):
|
class News(BaseAttributes):
|
||||||
"""News model."""
|
"""News model."""
|
||||||
|
image = models.ForeignKey(
|
||||||
|
'gallery.Image', null=True, blank=True, default=None,
|
||||||
|
verbose_name=_('News image'), on_delete=models.CASCADE)
|
||||||
news_type = models.ForeignKey(
|
news_type = models.ForeignKey(
|
||||||
NewsType, verbose_name=_('news type'), on_delete=models.CASCADE)
|
NewsType, verbose_name=_('news type'), on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ class NewsLocalizationMixinSerializer(serializers.ModelSerializer):
|
||||||
class NewsSerializer(NewsLocalizationMixinSerializer):
|
class NewsSerializer(NewsLocalizationMixinSerializer):
|
||||||
"""News serializer."""
|
"""News serializer."""
|
||||||
address = AddressSerializer()
|
address = AddressSerializer()
|
||||||
|
image = serializers.URLField(source='image.get_image_url')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.News
|
model = models.News
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
"""Utils app models."""
|
"""Utils app models."""
|
||||||
|
from os.path import exists
|
||||||
|
|
||||||
from django.contrib.auth.tokens import PasswordResetTokenGenerator
|
from django.contrib.auth.tokens import PasswordResetTokenGenerator
|
||||||
from django.contrib.gis.db import models
|
from django.contrib.gis.db import models
|
||||||
|
|
@ -83,6 +84,13 @@ class ImageMixin(models.Model):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_full_image_url(self, request, thumbnail_key=None):
|
||||||
|
"""Get full image url"""
|
||||||
|
if self.image and exists(self.image.path):
|
||||||
|
return request.build_absolute_uri(self.get_image(thumbnail_key).url)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
image_tag.short_description = _('Image')
|
image_tag.short_description = _('Image')
|
||||||
image_tag.allow_tags = True
|
image_tag.allow_tags = True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ PROJECT_APPS = [
|
||||||
'authorization.apps.AuthorizationConfig',
|
'authorization.apps.AuthorizationConfig',
|
||||||
'collection.apps.CollectionConfig',
|
'collection.apps.CollectionConfig',
|
||||||
'establishment.apps.EstablishmentConfig',
|
'establishment.apps.EstablishmentConfig',
|
||||||
|
'gallery.apps.GalleryConfig',
|
||||||
'location.apps.LocationConfig',
|
'location.apps.LocationConfig',
|
||||||
'main.apps.MainConfig',
|
'main.apps.MainConfig',
|
||||||
'news.apps.NewsConfig',
|
'news.apps.NewsConfig',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user