July 2018
Intermediate to advanced
324 pages
8h 14m
English
We are going to create two models—PhotoAlbum and Photo model, with a relationship of one-to-many. The following is the code snippet of the gallery/models.py file: File—gallery/models.py:
from django.db import modelsfrom django.utils.translation import gettext as _from imagekit.models import ImageSpecFieldfrom imagekit.processors import ResizeToFill# Create your models here.def upload_path(instance, filename): return '{}/{}'.format(instance.album.name, filename)class PhotoAlbum(models.Model): name = models.CharField(_('album name'), max_length=50) created_at = models.DateTimeField(auto_now_add=True, auto_now=False) updated_at = models.DateTimeField(auto_now=True) class Meta: db_table = 'photo_album' verbose_name = 'photo ...Read now
Unlock full access