Answer the question
In order to leave comments, you need to log in
Send image url?
There is a group model
class Group(models.Model):
group_name = models.CharField(max_length=100,, unique=True) # group's name
group_description = models.CharField(max_length=500, verbose_name='Опис') # short description of the group
group_image = models.ImageField(upload_to='base/static/images/', ')
images_for_slider = models.ManyToManyField('ImagesForSlider', related_name='group')
class ImagesForSlider(models.Model):
image = models.ImageField(upload_to='base/static/images/')
image_name = models.CharField(max_length=100, verbose_name='Назва', unique=True, default="Image")
def __str__(self):
return self.image_name
def get_img(self):
return self.image.url
group_name "!!!!!!!!!"
group_description "@@@@@@@@@@"
group_image "/base/static/base/static/images/git_aCw8bze.png"
images_for_slider
0 1
1 2
2 3
3 4
Answer the question
In order to leave comments, you need to log in
If I understand correctly, it is necessary to display links, not just IDs. For the manytomany field model, you need to make a separate serializer, something like this:
class ImagesForSliderSerializer(serializers.ModelSerializer):
class Meta:
model = ImagesForSlider
fields = ('id', 'image', 'image_name')
class GroupSerializer(serializers.ModelSerializer):
images_for_slider = ImagesForSliderSerializer(many=True)
class Meta:
model = Group
fields = (
# ...
'images_for_slider',
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question