mirror of
https://github.com/kennethreitz/photos.kennethreitz.org.git
synced 2026-06-21 07:00:57 +00:00
f9e276c487
Collections: optional date field (defaults to created_at display). Date picker on create form, shown on dashboard cards. Homepage: only shows cameras/lenses with 32+ images. View all links go to full filtered list pages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
import uuid
|
|
|
|
from django.db import models
|
|
|
|
from core.models import Image, User
|
|
|
|
|
|
class Collection(models.Model):
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='collections')
|
|
title = models.CharField(max_length=255)
|
|
slug = models.SlugField(max_length=255)
|
|
description = models.TextField(blank=True)
|
|
cover_image = models.ForeignKey(
|
|
Image, on_delete=models.SET_NULL, null=True, blank=True,
|
|
related_name='+'
|
|
)
|
|
visibility = models.CharField(
|
|
max_length=10,
|
|
choices=Image.Visibility.choices,
|
|
default=Image.Visibility.PUBLIC,
|
|
)
|
|
images = models.ManyToManyField(
|
|
Image, through='CollectionImage', related_name='collections'
|
|
)
|
|
date = models.DateField(
|
|
null=True, blank=True,
|
|
help_text="Optional display date (e.g. date of shoot). Defaults to creation date."
|
|
)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
class Meta:
|
|
ordering = ['-created_at']
|
|
unique_together = [('user', 'slug')]
|
|
|
|
def __str__(self) -> str:
|
|
return self.title
|
|
|
|
|
|
class CollectionImage(models.Model):
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
collection = models.ForeignKey(
|
|
Collection, on_delete=models.CASCADE, related_name='collection_images'
|
|
)
|
|
image = models.ForeignKey(
|
|
Image, on_delete=models.CASCADE, related_name='collection_entries'
|
|
)
|
|
sort_order = models.PositiveIntegerField(default=0)
|
|
added_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
class Meta:
|
|
ordering = ['sort_order']
|
|
unique_together = [('collection', 'image')]
|
|
|
|
def __str__(self) -> str:
|
|
return f"{self.collection} — {self.image}"
|