models.py
class Video(models.Model):
title = models.CharField(max_length=100, blank=True, default='')
details = models.TextField()
class VideoDetails(models.Model):
video = models.ForeignKey(Video, on_delete=models.CASCADE, related_name='videos')
images = models.ImageField(upload_to='images/video/%Y/%m/%d')
serializers.py
class VideoDetailsSerializer(serializers.ModelSerializer):
class Meta:
model = VideoDetails
fields = '__all__'
class VideoSerializer(serializers.ModelSerializer):
class Meta:
model = Video
fields = '__all__'
admin.py
class VideoDetailsInline(admin.TabularInline):
model = VideoDetails
class VideoAdmin(admin.ModelAdmin):
inlines = [VideoDetailsInline]
admin.site.register(Video, VideoAdmin)
As shown above, I uploaded 3 images for video 2. However, in my VideoList
view, I didn't get the urls of those images.
views.py
class VideoList(viewsets.ModelViewSet):
serializer_class = VideoSerializer
queryset = Video.objects.all()
How can I attach those image url in VideoDetail
to the queryset
of Video
? Need your help...