S
S
Smuzzzzi2019-01-12 14:49:23
Django
Smuzzzzi, 2019-01-12 14:49:23

How to return an empty value?

Model

def get_profile_cover_picture(self):
  default_cover = None
    if self.cover:
      return self.cover.url
    else:
      return default_cover

Serializers
def get_profile_cover_picture(self, obj):
  request = self.context.get('request')
  profile_cover_picture_url = obj.get_profile_cover_picture()
  return request.build_absolute_uri(profile_cover_picture_url)

Now
"profile_cover_picture" is returned: " localhost:8000/api/users/base_user_profile/admin "
I need that if cover is missing, then the string should be empty

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Smuzzzzi, 2019-01-12
@Smuzzzzi

def get_profile_cover_picture(self, obj):
    return obj.get_profile_cover_picture()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question