JourneyJoker/gallery/models.py

20 lines
727 B
Python
Raw Permalink Normal View History

2021-05-30 06:03:05 +00:00
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
2021-05-30 06:03:05 +00:00
from .helpers import get_upload_path
class Image(models.Model):
image = models.ImageField(upload_to=get_upload_path)
title = models.CharField(max_length=128, null=True, blank=True)
comment = models.TextField(null=True, blank=True)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
upload_path = models.CharField(max_length=256, null=True, blank=True)
@property
def url(self):
return self.image.url