diff --git a/django_web_galleries/web_galleries/models.py b/django_web_galleries/web_galleries/models.py index e32303d..78cedef 100644 --- a/django_web_galleries/web_galleries/models.py +++ b/django_web_galleries/web_galleries/models.py @@ -1,7 +1,12 @@ +import uuid + from django.db import models from django.core.exceptions import ValidationError from django.utils.translation import gettext as _ +def get_uuid(): + return str(uuid.uuid4()) + class Visitor(models.Model): """ Stores information about a visitor of this application. @@ -10,7 +15,8 @@ class Visitor(models.Model): """ session_id = models.CharField( _('A cookie set by this application to identify a visitor by session'), - max_length=50 + max_length=50, + default=get_uuid ) name = models.CharField( _('Human readable, self assigned name of the visitor'), @@ -67,6 +73,13 @@ class Image(models.Model): An image contains the path to the image file and several information like description, uploader and affiliation to galleries. """ + + title = models.CharField( + _('Title of the image'), + max_length=100, + null=True, + blank=True + ) description = models.TextField( _('An optional description of the Image'), null=True @@ -105,3 +118,11 @@ class Image(models.Model): related_name='images' ) + def __str__(self): + if self.title: + return self.title + elif self.description: + return self.description[:100] + else: + return super.__str__() +