Skip to content
Snippets Groups Projects
Commit 46e950f1 authored by Rafael László's avatar Rafael László :speech_balloon:
Browse files

return relative path for images

parent e5e012e6
No related branches found
No related tags found
1 merge request!2Dev
...@@ -3,7 +3,15 @@ from rest_framework import serializers ...@@ -3,7 +3,15 @@ from rest_framework import serializers
class ImageSerializer(serializers.ModelSerializer): class ImageSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Image model = Image
fields = ('image',) fields = ('image',)
def to_representation(self, instance):
response = super(
ImageSerializer,
self
).to_representation(instance)
if instance.image:
response['image'] = instance.image.url
return response
...@@ -14,7 +14,7 @@ class Mentor(models.Model): ...@@ -14,7 +14,7 @@ class Mentor(models.Model):
name = models.CharField(null=False, max_length=200) name = models.CharField(null=False, max_length=200)
text = models.TextField() text = models.TextField()
image = models.ImageField( image = models.ImageField(
upload_to='mentors/images/', null=True, blank=True) upload_to='public/mentors/images/', null=True, blank=True)
email = models.EmailField() email = models.EmailField()
def __str__(self): def __str__(self):
......
...@@ -12,3 +12,12 @@ class MentorSerializer(serializers.ModelSerializer): ...@@ -12,3 +12,12 @@ class MentorSerializer(serializers.ModelSerializer):
def get_mentor(self, obj): def get_mentor(self, obj):
return obj.mentor.full_name return obj.mentor.full_name
def to_representation(self, instance):
response = super(
MentorSerializer,
self
).to_representation(instance)
if instance.image:
response['image'] = instance.image.url
return response
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment