Created
June 10, 2020 18:40
-
-
Save walison17/b732ce6fa9c20a6d838ac4b68db3e8eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.contrib.staticfiles.storage import staticfiles_storage | |
DEFAULT_IMAGE = 'img/default.svg' | |
class Place(models.Model): | |
name = models.CharField(max_length=50, unique=True) | |
image = models.ImageField(upload_to="places/", blank=True, null=True) | |
def __str__(self): | |
return self.name | |
def get_image_url(self): | |
if not self.image: | |
return staticfiles_storage.url(DEFAULT_IMAGE) | |
return self.image.url | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment