Add cats to the admin and give them a more useful string representation

This commit is contained in:
Danielle McLean 2017-11-20 11:37:36 +11:00
parent 8fdaad5367
commit b63e2db584
Signed by untrusted user: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
2 changed files with 5 additions and 1 deletions

View file

@ -1,5 +1,5 @@
from django.contrib import admin from django.contrib import admin
from .models import Entry, Syndication from .models import Cat, Entry, Syndication
class SyndicationInline(admin.TabularInline): class SyndicationInline(admin.TabularInline):
@ -16,4 +16,5 @@ class EntryAdmin(admin.ModelAdmin):
) )
admin.site.register(Cat)
admin.site.register(Entry, EntryAdmin) admin.site.register(Entry, EntryAdmin)

View file

@ -28,6 +28,9 @@ class Cat(models.Model):
name = models.CharField(max_length=255, unique=True) name = models.CharField(max_length=255, unique=True)
slug = models.CharField(max_length=255, unique=True) slug = models.CharField(max_length=255, unique=True)
def __str__(self):
return '#' + self.name
@property @property
def url(self): def url(self):
return reverse('entries:cat', args=(self.slug,)) return reverse('entries:cat', args=(self.slug,))