-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a805e6f
commit 1f3d431
Showing
38 changed files
with
9,322 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.contrib import admin | ||
from blog.models import Blog, Category | ||
|
||
|
||
class BlogAdmin(admin.ModelAdmin): | ||
exclude = ['posted'] | ||
prepopulated_fields = {'slug': ('title',)} | ||
|
||
|
||
class CategoryAdmin(admin.ModelAdmin): | ||
prepopulated_fields = {'slug': ('title',)} | ||
|
||
admin.site.register(Blog, BlogAdmin) | ||
admin.site.register(Category, CategoryAdmin) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django import forms | ||
|
||
from .models import Blog | ||
|
||
class PostForm(forms.ModelForm): | ||
|
||
class Meta: | ||
model = Blog | ||
|
||
fields = ('title', 'slug', 'body') |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from django.db import models | ||
from django.db.models import permalink | ||
|
||
# Create your models here. | ||
|
||
class Blog(models.Model): | ||
title = models.CharField(max_length=100, unique=True) | ||
slug = models.SlugField(max_length=100, unique=True) | ||
body = models.TextField() | ||
posted = models.DateTimeField(db_index=True, auto_now_add=True) | ||
category = models.ForeignKey('blog.Category') | ||
|
||
def __unicode__(self): | ||
return '%s' % self.title | ||
|
||
@permalink | ||
def get_absolute_url(self): | ||
return ('view_blog_post', None, { 'slug': self.slug }) | ||
|
||
class Category(models.Model): | ||
title = models.CharField(max_length=100, db_index=True) | ||
slug = models.SlugField(max_length=100, db_index=True) | ||
|
||
def __unicode__(self): | ||
return '%s' % self.title | ||
|
||
@permalink | ||
def get_absolute_url(self): | ||
return ('view_blog_category', None, { 'slug': self.slug }) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
<html> | ||
<head> | ||
<title>{% block head_title %}Welcome to my blog{% endblock %}</title> | ||
</head> | ||
<body> | ||
|
||
<div class="page-header"> | ||
<a href="{% url 'blog.views.post_new' %}" class="top-menu"> | ||
</div> | ||
<h1>{% block title %}Welcome to my block{% endblock %}</h1> | ||
{% block content %} | ||
|
||
{% endblock %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% extends 'base.html' %} | ||
{% block title %}Welcome to my blog{% endblock %} | ||
|
||
{% block content %} | ||
<h2>Categories</h2> | ||
{% if categories %} | ||
<ul> | ||
{% for category in categories %} | ||
<li><a href="{{ category.get_absolute_url }}">{{ category.title }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
{% else %} | ||
<p>There are no posts.</p> | ||
{% endif %} | ||
|
||
<h2>Posts</h2> | ||
{% if posts %} | ||
<ul> | ||
{% for post in posts %} | ||
<li><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
{% else %} | ||
<p>There are no posts.</p> | ||
{% endif %} | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block content %} | ||
<h1>New post</h1> | ||
|
||
<form method="POST" class="post-form">{% csrf_token %} | ||
|
||
{{ form.as_p }} | ||
|
||
<button type="submit" class="save btn btn-default">Save</button> | ||
|
||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% extends 'base.html' %} | ||
{% block head_title %}Viewing category {{ category.title }}{% endblock %} | ||
{% block title %}{{ category.title }}{% endblock %} | ||
|
||
{% block content %} | ||
{% if posts %} | ||
<ul> | ||
{% for post in posts %} | ||
<li><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
{% else %} | ||
<p>There are no posts.</p> | ||
{% endif %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% extends 'base.html' %} | ||
{% block head_title %}{{ post.title }}{% endblock %} | ||
{% block title %}{{ post.title }}{% endblock %} | ||
|
||
{% block content %} | ||
{{ post.body }} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from blog.models import Blog,Category | ||
from django.shortcuts import render_to_response, get_object_or_404 | ||
from .forms import PostForm | ||
from django.http import HttpResponse | ||
|
||
def index(request): | ||
return render_to_response('index.html', { | ||
'categories': Category.objects.all(), | ||
'posts': Blog.objects.all()[:5] | ||
}) | ||
|
||
def view_post(request, slug): | ||
return render_to_response('view_post.html', { | ||
'post': get_object_or_404(Blog, slug=slug) | ||
}) | ||
|
||
def view_category(request, slug): | ||
category = get_object_or_404(Category, slug=slug) | ||
return render_to_response('view_category.html', { | ||
'category': category, | ||
'posts': Blog.objects.filter(category=category)[:5] | ||
}) | ||
|
||
def post_new(request): | ||
# global form | ||
if request.method == "POST": | ||
form = PostForm(request.POST) | ||
if form.is_valid(): | ||
post = form.save(commit=False) | ||
post.title = request.user | ||
post.save() | ||
|
||
#form.save | ||
else: | ||
# redirect(new_post) | ||
|
||
return redirect('blog.views.post_detail', pk=post.pk) | ||
else: | ||
form = PostForm() | ||
return render_to_response('post_edit.html', {'form': form}) |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wopaproject.settings") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
Oops, something went wrong.