Set up Enabled/Published as boolean properties.

This commit is contained in:
Josh Washburne 2018-01-04 16:28:59 -05:00
parent 0d346adee9
commit 4555de206a
2 changed files with 14 additions and 32 deletions

View file

@ -16,7 +16,7 @@ class ArtistInline(admin.TabularInline):
@admin.register(Album) @admin.register(Album)
class AlbumAdmin(admin.ModelAdmin): class AlbumAdmin(admin.ModelAdmin):
# Detail List display # Detail List display
list_display = ('title', 'is_enabled', 'is_published') list_display = ('title', '_is_enabled', '_is_published')
search_fields = ['title'] search_fields = ['title']
actions = ['publish_items'] actions = ['publish_items']
@ -36,12 +36,6 @@ class AlbumAdmin(admin.ModelAdmin):
}) })
) )
def is_enabled(self, obj):
return not obj.disabled
def is_published(self, obj):
return obj.is_published
def publish_items(self, request, queryset): def publish_items(self, request, queryset):
rows_updated = queryset.update(published_date=timezone.now()) rows_updated = queryset.update(published_date=timezone.now())
if rows_updated == 1: if rows_updated == 1:
@ -58,8 +52,8 @@ class ArtistAdmin(admin.ModelAdmin):
list_display = ('first_name', list_display = ('first_name',
'alias', 'alias',
'last_name', 'last_name',
'is_enabled', '_is_enabled',
'is_published') '_is_published')
search_fields = ['first_name', 'alias', 'last_name'] search_fields = ['first_name', 'alias', 'last_name']
actions = ['publish_items'] actions = ['publish_items']
@ -79,12 +73,6 @@ class ArtistAdmin(admin.ModelAdmin):
}) })
) )
def is_enabled(self, obj):
return not obj.disabled
def is_published(self, obj):
return obj.is_published
def publish_items(self, request, queryset): def publish_items(self, request, queryset):
rows_updated = queryset.update(published_date=timezone.now()) rows_updated = queryset.update(published_date=timezone.now())
if rows_updated == 1: if rows_updated == 1:
@ -98,7 +86,7 @@ class ArtistAdmin(admin.ModelAdmin):
@admin.register(Game) @admin.register(Game)
class GameAdmin(admin.ModelAdmin): class GameAdmin(admin.ModelAdmin):
# Detail List display # Detail List display
list_display = ('title', 'is_enabled', 'is_published') list_display = ('title', '_is_enabled', '_is_published')
search_fields = ['title'] search_fields = ['title']
actions = ['publish_items'] actions = ['publish_items']
@ -118,12 +106,6 @@ class GameAdmin(admin.ModelAdmin):
}) })
) )
def is_enabled(self, obj):
return not obj.disabled
def is_published(self, obj):
return obj.is_published
def publish_items(self, request, queryset): def publish_items(self, request, queryset):
rows_updated = queryset.update(published_date=timezone.now()) rows_updated = queryset.update(published_date=timezone.now())
if rows_updated == 1: if rows_updated == 1:
@ -144,8 +126,8 @@ class SongAdmin(admin.ModelAdmin):
list_display = ('title', list_display = ('title',
'game', 'game',
'artist_list', 'artist_list',
'is_enabled', '_is_enabled',
'is_published') '_is_published')
search_fields = ['title'] search_fields = ['title']
actions = ['publish_items'] actions = ['publish_items']
@ -187,12 +169,6 @@ class SongAdmin(admin.ModelAdmin):
def artist_list(self, obj): def artist_list(self, obj):
return ', '.join([a.full_name for a in obj.artists.all()]) return ', '.join([a.full_name for a in obj.artists.all()])
def is_enabled(self, obj):
return not obj.disabled
def is_published(self, obj):
return obj.is_published
def publish_items(self, request, queryset): def publish_items(self, request, queryset):
rows_updated = queryset.update(published_date=timezone.now()) rows_updated = queryset.update(published_date=timezone.now())
if rows_updated == 1: if rows_updated == 1:

View file

@ -29,6 +29,11 @@ class Disableable(models.Model):
self.disabled_reason = '' self.disabled_reason = ''
self.save() self.save()
def _is_enabled(self):
return not self.disabled
_is_enabled.boolean = True
is_enabled = property(_is_enabled)
class Publishable(models.Model): class Publishable(models.Model):
""" """
@ -49,8 +54,9 @@ class Publishable(models.Model):
self.published_date = date self.published_date = date
self.save() self.save()
@property def _is_published(self):
def is_published(self):
if self.published_date is not None: if self.published_date is not None:
return self.published_date < timezone.now() return self.published_date < timezone.now()
return False return False
_is_published.boolean = True
is_published = property(_is_published)