muistox/gallery/models.py

51 lines
1.6 KiB
Python
Raw Normal View History

2024-12-29 23:25:03 +02:00
from datetime import datetime
2024-12-28 12:21:29 +02:00
from django.db import models
2024-12-29 23:25:03 +02:00
from django.utils.text import slugify
2024-12-28 12:21:29 +02:00
# Create your models here.
2024-12-29 17:35:10 +02:00
2024-12-29 23:25:03 +02:00
2024-12-29 17:35:10 +02:00
class City(models.Model):
name = models.CharField(max_length=150, unique=True, verbose_name="City")
class Meta:
verbose_name_plural = "Cities"
def __str__(self):
return '{}'.format(self.name)
2024-12-29 23:25:03 +02:00
2024-12-29 17:35:10 +02:00
class Location(models.Model):
place = models.CharField(max_length=250, blank=True, null=False, verbose_name="Place")
city = models.ForeignKey(City, on_delete=models.CASCADE, related_name='places', verbose_name="City")
class Meta:
verbose_name_plural = "Locations"
unique_together = ('place', "city")
def __str__(self):
if self.place:
return '{0}, {1}'.format(self.city, self.place)
else:
return '{}'.format(self.city)
2024-12-29 23:25:03 +02:00
class Album(models.Model):
name = models.CharField(max_length=150, unique=True, verbose_name="Album")
slug = models.SlugField(max_length=150, unique=True, verbose_name="Slug")
location = models.ForeignKey(Location, blank=True, null=True, on_delete=models.SET_NULL, related_name='albums', verbose_name="Location")
album_date = models.DateField(default=datetime.now, verbose_name="Album Date")
is_public = models.BooleanField(default=False, verbose_name="Published")
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.name)
super(Album, self).save(*args, **kwargs)
class Meta:
verbose_name_plural = "Albums"
def __str__(self):
return '{}'.format(self.name)