Skip to content

Commit

Permalink
my second commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shakirandagire committed Aug 4, 2014
1 parent a805e6f commit 1f3d431
Show file tree
Hide file tree
Showing 38 changed files with 9,322 additions and 0 deletions.
Empty file added blog/__init__.py
Empty file.
Binary file added blog/__init__.pyc
Binary file not shown.
14 changes: 14 additions & 0 deletions blog/admin.py
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 added blog/admin.pyc
Binary file not shown.
10 changes: 10 additions & 0 deletions blog/forms.py
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 added blog/forms.pyc
Binary file not shown.
29 changes: 29 additions & 0 deletions blog/models.py
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 added blog/models.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions blog/templates/base.html
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>
27 changes: 27 additions & 0 deletions blog/templates/index.html
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 %}
13 changes: 13 additions & 0 deletions blog/templates/post_edit.html
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 %}
15 changes: 15 additions & 0 deletions blog/templates/view_category.html
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 %}
7 changes: 7 additions & 0 deletions blog/templates/view_post.html
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 %}
3 changes: 3 additions & 0 deletions blog/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
40 changes: 40 additions & 0 deletions blog/views.py
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 added blog/views.pyc
Binary file not shown.
Binary file added db.sqlite3
Binary file not shown.
10 changes: 10 additions & 0 deletions manage.py
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)
Loading

0 comments on commit 1f3d431

Please sign in to comment.