Add Album model
This commit is contained in:
parent
80cf963b7f
commit
1a65aec740
3 changed files with 51 additions and 8 deletions
|
@ -1,11 +1,10 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from gallery.models import City, Location
|
from gallery.models import Album, City, Location
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CityAdmin(admin.ModelAdmin):
|
class CityAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name',)
|
list_display = ('name',)
|
||||||
search_fields = ('name',)
|
search_fields = ('name',)
|
||||||
|
@ -13,9 +12,6 @@ class CityAdmin(admin.ModelAdmin):
|
||||||
list_per_page = 30
|
list_per_page = 30
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(City, CityAdmin)
|
|
||||||
|
|
||||||
|
|
||||||
class LocationAdmin(admin.ModelAdmin):
|
class LocationAdmin(admin.ModelAdmin):
|
||||||
list_display = ('city', 'place')
|
list_display = ('city', 'place')
|
||||||
list_filter = ('city',)
|
list_filter = ('city',)
|
||||||
|
@ -23,5 +19,15 @@ class LocationAdmin(admin.ModelAdmin):
|
||||||
search_fields = ('place', 'city__name',)
|
search_fields = ('place', 'city__name',)
|
||||||
list_per_page = 30
|
list_per_page = 30
|
||||||
|
|
||||||
|
class AlbumAdmin(admin.ModelAdmin):
|
||||||
|
prepopulated_fields = {'slug': ('name',)}
|
||||||
|
list_display = ('__str__',)
|
||||||
|
search_fields = ('name',)
|
||||||
|
ordering = ('name',)
|
||||||
|
list_per_page = 30
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(City, CityAdmin)
|
||||||
admin.site.register(Location, LocationAdmin)
|
admin.site.register(Location, LocationAdmin)
|
||||||
|
admin.site.register(Album, AlbumAdmin)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# Generated by Django 5.1.4 on 2024-12-29 13:38
|
# Generated by Django 5.1.4 on 2024-12-29 21:23
|
||||||
|
|
||||||
|
import datetime
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
@ -34,4 +35,18 @@ class Migration(migrations.Migration):
|
||||||
'unique_together': {('place', 'city')},
|
'unique_together': {('place', 'city')},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Album',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=150, unique=True, verbose_name='Album')),
|
||||||
|
('slug', models.SlugField(max_length=150, unique=True, verbose_name='Slug')),
|
||||||
|
('album_date', models.DateField(default=datetime.datetime.now, verbose_name='Album Date')),
|
||||||
|
('is_public', models.BooleanField(default=False, verbose_name='Published')),
|
||||||
|
('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='albums', to='gallery.location', verbose_name='Location')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name_plural': 'Albums',
|
||||||
|
},
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.utils.text import slugify
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
class City(models.Model):
|
class City(models.Model):
|
||||||
name = models.CharField(max_length=150, unique=True, verbose_name="City")
|
name = models.CharField(max_length=150, unique=True, verbose_name="City")
|
||||||
|
|
||||||
|
@ -10,9 +14,8 @@ class City(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{}'.format(self.name)
|
return '{}'.format(self.name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Location(models.Model):
|
class Location(models.Model):
|
||||||
place = models.CharField(max_length=250, blank=True, null=False, verbose_name="Place")
|
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")
|
city = models.ForeignKey(City, on_delete=models.CASCADE, related_name='places', verbose_name="City")
|
||||||
|
@ -26,3 +29,22 @@ class Location(models.Model):
|
||||||
return '{0}, {1}'.format(self.city, self.place)
|
return '{0}, {1}'.format(self.city, self.place)
|
||||||
else:
|
else:
|
||||||
return '{}'.format(self.city)
|
return '{}'.format(self.city)
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
Loading…
Reference in a new issue