added transfer for gallery app
This commit is contained in:
parent
110d0872da
commit
cb3ad6bb96
20
apps/gallery/migrations/0002_auto_20191023_1207.py
Normal file
20
apps/gallery/migrations/0002_auto_20191023_1207.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-23 12:07
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
import easy_thumbnails.fields
|
||||||
|
import utils.methods
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('gallery', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='image',
|
||||||
|
name='image',
|
||||||
|
field=easy_thumbnails.fields.ThumbnailerImageField(max_length=255, upload_to=utils.methods.image_path, verbose_name='Image file'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -9,7 +9,7 @@ class Image(ProjectBaseMixin, ImageMixin):
|
||||||
"""Image model."""
|
"""Image model."""
|
||||||
|
|
||||||
image = ThumbnailerImageField(upload_to=image_path,
|
image = ThumbnailerImageField(upload_to=image_path,
|
||||||
verbose_name=_('Image file'))
|
verbose_name=_('Image file'), max_length=255)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
|
||||||
21
apps/gallery/transfer_data.py
Normal file
21
apps/gallery/transfer_data.py
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
from django.db.models import Value, IntegerField, F
|
||||||
|
from pprint import pprint
|
||||||
|
from gallery.models import Image
|
||||||
|
from transfer.models import MercuryImages
|
||||||
|
from transfer.serializers.gallery import ImageSerializer
|
||||||
|
|
||||||
|
|
||||||
|
def transfer_gallery():
|
||||||
|
queryset = MercuryImages.objects.all()
|
||||||
|
|
||||||
|
serialized_data = ImageSerializer(data=list(queryset.values()), many=True)
|
||||||
|
if serialized_data.is_valid():
|
||||||
|
serialized_data.save()
|
||||||
|
else:
|
||||||
|
pprint(f"News serializer errors: {serialized_data.errors}")
|
||||||
|
|
||||||
|
|
||||||
|
data_types = {
|
||||||
|
"gallery": [transfer_gallery]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -14,7 +14,8 @@ class Command(BaseCommand):
|
||||||
'account',
|
'account',
|
||||||
'subscriber',
|
'subscriber',
|
||||||
'recipe',
|
'recipe',
|
||||||
'partner'
|
'partner',
|
||||||
|
'gallery'
|
||||||
]
|
]
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
|
|
||||||
15
apps/transfer/serializers/gallery.py
Normal file
15
apps/transfer/serializers/gallery.py
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
from gallery.models import Image
|
||||||
|
|
||||||
|
|
||||||
|
class ImageSerializer(serializers.ModelSerializer):
|
||||||
|
attachment_file_name = serializers.CharField(source="image")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Image
|
||||||
|
fields = (
|
||||||
|
"attachment_file_name",
|
||||||
|
)
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
return Image.objects.create(**validated_data)
|
||||||
Loading…
Reference in New Issue
Block a user