added blog entry categories

This commit is contained in:
Otto Naderer 2016-10-24 18:43:54 +02:00
parent 833e19a3cc
commit 79e2baa696
4 changed files with 25 additions and 3 deletions

View File

@ -1,6 +1,6 @@
from django import forms
from django.forms import ModelForm, Textarea
from blogapp.models import blogentry, blogcomment
from blogapp.models import blogentry, blogcomment, blogcategory
from django.contrib import admin
class blogentryAdminForm(forms.ModelForm):
@ -12,6 +12,12 @@ class blogentryAdminForm(forms.ModelForm):
'body': forms.Textarea(attrs={'cols': 80, 'rows': 20}),
}
class blogcategoryAdminForm(forms.ModelForm):
class Meta:
model = blogcategory
fields = '__all__'
class blogentryAdmin(admin.ModelAdmin):
form = blogentryAdminForm
list_display = ('header', )
@ -19,5 +25,10 @@ class blogentryAdmin(admin.ModelAdmin):
class blogcommentAdmin(admin.ModelAdmin):
list_display = ('date', )
class blogcategoryAdmin(admin.ModelAdmin):
form = blogentryAdminForm
list_display = ('name',)
admin.site.register(blogentry, blogentryAdmin)
admin.site.register(blogcomment, blogcommentAdmin)
admin.site.register(blogcategory, blogcategoryAdmin)

View File

@ -1,12 +1,21 @@
from django.db import models
from django.contrib.auth.models import User
class blogcategory(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class blogentry(models.Model):
user = models.ForeignKey(User)
date = models.DateTimeField('date')
header = models.CharField(max_length=100)
intro = models.CharField(max_length=1000)
body = models.CharField(max_length=10000)
categories = models.ManyToManyField('blogcategory')
published = models.BooleanField(default=False)
class blogcomment(models.Model):

View File

@ -10,7 +10,9 @@
{% if blogentry.published %}
<h1>{{ blogentry.header }}</h1>
<small>posted on: {{blogentry.date}} by {{blogentry.user.username}}</small>
<p>{{blogentry.intro|linebreaks}}</p><a href="{% url 'detail' blogentry.id %}">Read more...</a><br/>
<p>{{blogentry.intro|linebreaks}}
<small>Filed under: {% for category in blogentry.categories.all %} {{ category }} {% endfor %}</small>
</p><a href="{% url 'detail' blogentry.id %}">Read more...</a><br/>
{% endif %}
{% endfor %}
{% else %}

View File

@ -46,7 +46,7 @@ div#main{
img#intext{
padding-top:1em;
padding-bottom:1em;
display: block;
margin-left: auto;
margin-right: auto;