From bce03d05006092603e0069d4ae577cc04dd80e5f Mon Sep 17 00:00:00 2001 From: reverend Date: Sun, 18 Dec 2022 09:18:50 +0100 Subject: [PATCH] Squashed commit of the following: commit e08aecabb4db848b495f86c6095fd0ee1edc05be Author: reverend Date: Sun Dec 18 09:15:25 2022 +0100 --- django_web_galleries/web_galleries/models.py | 106 ++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/django_web_galleries/web_galleries/models.py b/django_web_galleries/web_galleries/models.py index 71a8362..e32303d 100644 --- a/django_web_galleries/web_galleries/models.py +++ b/django_web_galleries/web_galleries/models.py @@ -1,3 +1,107 @@ from django.db import models +from django.core.exceptions import ValidationError +from django.utils.translation import gettext as _ + +class Visitor(models.Model): + """ + Stores information about a visitor of this application. + No personal information is gathered, the name is optional and can be anything. + The name has to be unique, tho. + """ + session_id = models.CharField( + _('A cookie set by this application to identify a visitor by session'), + max_length=50 + ) + name = models.CharField( + _('Human readable, self assigned name of the visitor'), + null=True, + default=None, + max_length=50, + unique=True + ) + + +class Gallery(models.Model): + """ + A gallery is a collection of multiple images. + It must be + """ + title = models.CharField( + _('Optional title for this gallery'), + null=True, + max_length=100 + ) + private = models.BooleanField( + _('Wether the gallery is vsibile publicly or to certain users only'), + default=False, + blank=True + ) + access_code = models.CharField( + _('Code to access private galleries'), + null=True, + max_length=32 + ) + + created_by = models.ForeignKey( + Visitor, + verbose_name=_('Visitor who created the gallery'), + related_name='created_galleries', + on_delete=models.CASCADE + ) + + visitors = models.ManyToManyField( + Visitor, + verbose_name=_('Visitors that a part of this gallery'), + related_name='linked_galleries' + ) + + def clean(self): + if self.private and access_code is None: + raise ValidationErrorr('Private gallery needs an access code') + if len(self.visitors.all()) > 10: + raise ValidationError('Gallery can not have more than 10 visitors assigned') + + +class Image(models.Model): + """ + An image contains the path to the image file and several information + like description, uploader and affiliation to galleries. + """ + description = models.TextField( + _('An optional description of the Image'), + null=True + ) + image_file = models.ImageField( + _('File of the image'), + upload_to='web_galleries/uploads/' + ) + + private = models.BooleanField( + _('Wether this image is visible publicly or to certain users only'), + default=False, + blank=True + ) + access_code = models.CharField( + _('Code to access private images'), + null=True, + max_length=32 + ) + + uploaded_by = models.ForeignKey( + Visitor, + verbose_name=_('Which visitor uploaded this picture'), + null=True, + related_name='uploaded_images', + on_delete=models.SET_NULL + ) + uploaded_when = models.DateTimeField( + _('When this picture was uploaded'), + auto_now_add=True + ) + + galleries = models.ManyToManyField( + Gallery, + verbose_name=_('What galleries this image is in'), + related_name='images' + ) -# Create your models here.