|
|
|
|
@ -130,14 +130,14 @@ class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
) |
|
|
|
|
elif c['type'] == 'image': |
|
|
|
|
if 'id' in c['data'] and c['data']['id']: |
|
|
|
|
i = Image.objects.get(id=c['data']['id']) |
|
|
|
|
i.position = c['data']['position'] |
|
|
|
|
i.title = c['data']['title'] |
|
|
|
|
i.course = course |
|
|
|
|
i.img = ImageObject.objects.get(id=c['data']['img']) |
|
|
|
|
i.save() |
|
|
|
|
image = Image.objects.get(id=c['data']['id']) |
|
|
|
|
image.position = c['data']['position'] |
|
|
|
|
image.title = c['data']['title'] |
|
|
|
|
image.course = course |
|
|
|
|
image.img = ImageObject.objects.get(id=c['data']['img']) |
|
|
|
|
image.save() |
|
|
|
|
else: |
|
|
|
|
i = Image.objects.create( |
|
|
|
|
image = Image.objects.create( |
|
|
|
|
position=c['data']['position'], |
|
|
|
|
title=c['data']['title'], |
|
|
|
|
course=course, |
|
|
|
|
@ -175,6 +175,30 @@ class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
course=course, |
|
|
|
|
url=c['data']['url'], |
|
|
|
|
) |
|
|
|
|
elif c['type'] == 'images': |
|
|
|
|
if 'id' in c['data'] and c['data']['id']: |
|
|
|
|
g = Gallery.objects.get(id=c['data']['id']) |
|
|
|
|
g.position = c['data']['position'] |
|
|
|
|
g.title = c['data']['title'] |
|
|
|
|
g.save() |
|
|
|
|
if 'images' in c['data']: |
|
|
|
|
for image in c['data']['images']: |
|
|
|
|
gi = GalleryImage.objects.create( |
|
|
|
|
gallery=g, |
|
|
|
|
img=ImageObject.objects.get(id=image['id']) |
|
|
|
|
) |
|
|
|
|
else: |
|
|
|
|
g = Gallery.objects.create( |
|
|
|
|
position=c['data']['position'], |
|
|
|
|
title=c['data']['title'], |
|
|
|
|
) |
|
|
|
|
if 'images' in c['data']: |
|
|
|
|
for image in c['data']['images']: |
|
|
|
|
gi = GalleryImage.objects.create( |
|
|
|
|
gallery=g, |
|
|
|
|
img=ImageObject.objects.get(id=image['id']), |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
for material in materials: |
|
|
|
|
if 'id' in material and material['id']: |
|
|
|
|
m = Material.objects.get(id=material['id']) |
|
|
|
|
@ -195,22 +219,26 @@ class CourseCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
if 'id' in gallery and gallery['id']: |
|
|
|
|
g = Gallery.objects.get(id=gallery['id']) |
|
|
|
|
g.title = gallery.get('title', g.title) |
|
|
|
|
g.course = course |
|
|
|
|
g.position = 0 |
|
|
|
|
g.save() |
|
|
|
|
else: |
|
|
|
|
g = Gallery.objects.create( |
|
|
|
|
title=gallery.get('title', '') |
|
|
|
|
title=gallery.get('title', ''), |
|
|
|
|
course=course, |
|
|
|
|
position=0, |
|
|
|
|
) |
|
|
|
|
if 'images' in gallery: |
|
|
|
|
for i in gallery['images']: |
|
|
|
|
if 'id' in i and i['id']: |
|
|
|
|
gi = GalleryImage.objects.get(id=i['id']) |
|
|
|
|
for image in gallery['images']: |
|
|
|
|
if 'id' in image and image['id']: |
|
|
|
|
gi = GalleryImage.objects.get(id=image['id']) |
|
|
|
|
gi.gallery = g |
|
|
|
|
gi.img = i['img'] |
|
|
|
|
gi.img = image['img'] |
|
|
|
|
gi.save() |
|
|
|
|
else: |
|
|
|
|
gi = GalleryImage.objects.create( |
|
|
|
|
gallery=g, |
|
|
|
|
img=i['img'], |
|
|
|
|
img=image['img'], |
|
|
|
|
) |
|
|
|
|
course.gallery = g |
|
|
|
|
course.save() |
|
|
|
|
@ -286,14 +314,14 @@ class LessonCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
) |
|
|
|
|
elif c['type'] == 'image': |
|
|
|
|
if 'id' in c['data'] and c['data']['id']: |
|
|
|
|
i = Image.objects.get(id=c['data']['id']) |
|
|
|
|
i.position = c['data']['position'] |
|
|
|
|
i.title = c['data']['title'] |
|
|
|
|
i.lesson = lesson |
|
|
|
|
i.img = ImageObject.objects.get(id=c['data']['img']) |
|
|
|
|
i.save() |
|
|
|
|
image = Image.objects.get(id=c['data']['id']) |
|
|
|
|
image.position = c['data']['position'] |
|
|
|
|
image.title = c['data']['title'] |
|
|
|
|
image.lesson = lesson |
|
|
|
|
image.img = ImageObject.objects.get(id=c['data']['img']) |
|
|
|
|
image.save() |
|
|
|
|
else: |
|
|
|
|
i = Image.objects.create( |
|
|
|
|
image = Image.objects.create( |
|
|
|
|
position=c['data']['position'], |
|
|
|
|
title=c['data']['title'], |
|
|
|
|
lesson=lesson, |
|
|
|
|
@ -331,6 +359,29 @@ class LessonCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
lesson=lesson, |
|
|
|
|
url=c['data']['url'], |
|
|
|
|
) |
|
|
|
|
elif c['type'] == 'images': |
|
|
|
|
if 'id' in c['data'] and c['data']['id']: |
|
|
|
|
g = Gallery.objects.get(id=c['data']['id']) |
|
|
|
|
g.position = c['data']['position'] |
|
|
|
|
g.title = c['data']['title'] |
|
|
|
|
g.save() |
|
|
|
|
if 'images' in c['data']: |
|
|
|
|
for image in c['data']['images']: |
|
|
|
|
gi = GalleryImage.objects.create( |
|
|
|
|
gallery=g, |
|
|
|
|
img=ImageObject.objects.get(id=image['id']), |
|
|
|
|
) |
|
|
|
|
else: |
|
|
|
|
g = Gallery.objects.create( |
|
|
|
|
position=c['data']['position'], |
|
|
|
|
title=c['data']['title'], |
|
|
|
|
) |
|
|
|
|
if 'images' in c['data']: |
|
|
|
|
for image in c['data']['images']: |
|
|
|
|
gi = GalleryImage.objects.create( |
|
|
|
|
gallery=g, |
|
|
|
|
img=ImageObject.objects.get(id=image['id']), |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def create(self, validated_data): |
|
|
|
|
content = validated_data.pop('content', []) |
|
|
|
|
|