Answer the question
In order to leave comments, you need to log in
How to serialize the same object in different ways?
Hello.
The question is, how can one and the same object be serialized differently depending on the contents of another field?
Model:
class Images(models.Model):
file_name = models.FileField(upload_to = get_file_path_image)
ordering = models.IntegerField()
section = models.ForeignKey(Sections, related_name = "images")
icon = models.FileField(upload_to = get_file_path_icon)
icon_x = models.CharField(max_length = 500)
icon_y = models.CharField(max_length = 500)
text = models.CharField(max_length = 500)
link_type = models.CharField(max_length = 500)
link = models.FileField(upload_to = get_file_path_feature)
def get_full_path_link(self, obj):
if str(obj.link_type) == u'Video':
return "http://ec***********.eu-west-1.compute.amazonaws.com" + obj.link.url
Answer the question
In order to leave comments, you need to log in
And what is the question? :-)
You have a get_full_path_link method - do whatever you want in it.
Well, or I misunderstood the question.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question