Merge branch 'better_examples2' of git://github.com/bootandy/django-admin2 into bootandy-better_examples2

This commit is contained in:
Daniel Greenfeld 2013-07-14 10:55:47 +02:00
commit 99b9285f80
6 changed files with 154 additions and 15 deletions

View file

@ -21,7 +21,7 @@ class Post(models.Model):
class Comment(models.Model):
post = models.ForeignKey(Post, verbose_name=_('post'))
post = models.ForeignKey(Post, verbose_name=_('post'), related_name="comments")
body = models.TextField(verbose_name=_('body'))
def __unicode__(self):

View file

@ -0,0 +1,54 @@
{% extends "base.html" %}
{% load staticfiles %}
{% block content %}
<div class="row-fluid">
<div class="span10">
<h3> <a href='{% url 'blog_list' %}'>Back to the Blog</a> </h3>
<h3>
{{ post.title }}
</h3>
{% if post.published %}
<p>
{{ post.body }}
</p>
<ul>
{% for comment in post.comments.all %}
<li>{{ comment.body }}</li>
{% empty %}
<li>No comments yet</li>
{% endfor %}
</ul>
{% else %}
<p> Unpublished - publish it in <a href="/admin2/">admin2</a> </p>
{% endif %}
</div>
</div>
<hr />
<div class="row-fluid">
<div class="span5">
<h4>The original <a href="/admin/">Django Admin</a></h4>
<a href="/admin/">
<img class="img-polaroid" src="{% static 'img/admin.png' %}" />
</a>
<p>Powered by django.contrib.admin. This is just here for reference.</p>
</div>
<div class="offset1 span5">
<h4>The new <a href="/admin2/">Admin2</a></h4>
<a href="/admin2/">
<img class="img-polaroid" src="{% static 'img/admin2.png' %}" />
</a>
<p>Powered by django-admin2.</p>
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,64 @@
{% extends "base.html" %}
{% load staticfiles %}
{% block content %}
<div class="row-fluid">
<div class="span10">
<h1>The blog of Example.com</h1>
{% for post in post_list %}
<h3>
<a href="{% url 'blog_detail' post.pk %}">
{{ post.title }}
</a>
</h3>
{% if post.published %}
<p>
{{ post.body }}
</p>
{% else %}
<p> Unpublished - publish it in <a href="/admin2/">admin2</a> </p>
{% endif %}
{% empty %}
<h3>Imagine that this is a real site</h3>
<p>Pretend that this is the homepage of a big Django site.</p>
<p>Imagine lots of things are here:</p>
<ul>
<li>A blog</li>
<li>Comments</li>
<li>And so on...</li>
</ul>
<p>In other words, these are items that we can introspect through the Django admin.</p>
<h3>Under the hood</h3>
<p>Now, explore the Django admin for example.com. Click on either of the following:</p>
{% endfor %}
</div>
</div>
<div class="row-fluid">
<div class="span5">
<h4>The original <a href="/admin/">Django Admin</a></h4>
<a href="/admin/">
<img class="img-polaroid" src="{% static 'img/admin.png' %}" />
</a>
<p>Powered by django.contrib.admin. This is just here for reference.</p>
</div>
<div class="offset1 span5">
<h4>The new <a href="/admin2/">Admin2</a></h4>
<a href="/admin2/">
<img class="img-polaroid" src="{% static 'img/admin2.png' %}" />
</a>
<p>Powered by django-admin2.</p>
</div>
</div>
{% endblock %}

View file

@ -176,11 +176,14 @@ class PostCreateViewTest(BaseIntegrationTest):
self.assertEqual(response.status_code, 200)
def test_create_post(self):
# Generated by inspecting the request with the pdb debugger
post_data = {
"comment_set-TOTAL_FORMS": u'2',
"comment_set-INITIAL_FORMS": u'0',
"comment_set-MAX_NUM_FORMS": u'',
"comment_set-0-body": u'Comment Body',
"comments-TOTAL_FORMS": u'2',
"comments-INITIAL_FORMS": u'0',
"comments-MAX_NUM_FORMS": u'',
"comments-0-body": u'Comment Body',
'comments-0-post': '',
'comments-0-id': '',
"title": "A Post Title",
"body": "a_post_body",
}
@ -189,7 +192,6 @@ class PostCreateViewTest(BaseIntegrationTest):
post_data,
follow=True)
self.assertTrue(Post.objects.filter(title="A Post Title").exists())
Post.objects.get(title="A Post Title")
Comment.objects.get(body="Comment Body")
self.assertRedirects(response, reverse("admin2:blog_post_index"))
@ -199,9 +201,12 @@ class PostCreateViewTest(BaseIntegrationTest):
page redirects the user to the model create page.
"""
post_data = {
"comment_set-TOTAL_FORMS": u'2',
"comment_set-INITIAL_FORMS": u'0',
"comment_set-MAX_NUM_FORMS": u'',
"comments-TOTAL_FORMS": u'2',
"comments-INITIAL_FORMS": u'0',
"comments-MAX_NUM_FORMS": u'',
"comments-0-body": u'Comment Body',
'comments-0-post': '',
'comments-0-id': '',
"title": "A Post Title",
"body": "a_post_body",
"_addanother": ""
@ -218,9 +223,9 @@ class PostCreateViewTest(BaseIntegrationTest):
the user to the model update form.
"""
post_data = {
"comment_set-TOTAL_FORMS": u'2',
"comment_set-INITIAL_FORMS": u'0',
"comment_set-MAX_NUM_FORMS": u'',
"comments-TOTAL_FORMS": u'2',
"comments-INITIAL_FORMS": u'0',
"comments-MAX_NUM_FORMS": u'',
"title": "Unique",
"body": "a_post_body",
"_continue": ""

View file

@ -1 +1,14 @@
# Create your views here.
#from django.shortcuts import render
from django.views.generic import ListView, DetailView
from .models import Post
class BlogListView(ListView):
model = Post
template_name = 'blog_list.html'
class BlogDetailView(DetailView):
model = Post
template_name = 'blog_detail.html'

View file

@ -1,6 +1,7 @@
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.views.generic import TemplateView
from blog.views import BlogListView, BlogDetailView
admin.autodiscover()
@ -11,5 +12,7 @@ djadmin2.default.autodiscover()
urlpatterns = patterns('',
url(r'^admin2/', include(djadmin2.default.urls)),
url(r'^admin/', include(admin.site.urls)),
url(r'^$', TemplateView.as_view(template_name="blog/home.html")),
url(r'^blog/', BlogListView.as_view(template_name="blog/blog_list.html"), name='blog_list'),
url(r'^blog_detail(?P<pk>\d+)/$', BlogDetailView.as_view(template_name="blog/blog_detail.html"), name='blog_detail'),
url(r'^$', BlogListView.as_view(template_name="blog/blog_list.html"), name='blog_list'),
)