-
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.
Some tutorials for Django ticket #18581
- Loading branch information
1 parent
c432c9b
commit 696b7ab
Showing
8 changed files
with
62 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,25 @@ | ||
from django.contrib import admin | ||
from djangoproject.models import Author, Article | ||
|
||
class AuthorAdmin(admin.ModelAdmin): | ||
pass | ||
|
||
class ArticleAdmin(admin.ModelAdmin): | ||
list_display = ['title', 'status'] | ||
ordering = ['title'] | ||
actions = ['make_published'] | ||
|
||
def make_published(self, request, queryset): | ||
rows_updated = queryset.update(status='p') | ||
if rows_updated == 1: | ||
message_bit = "1 story was" | ||
else: | ||
message_bit = "%s stories were" % rows_updated | ||
self.message_user(request, "%s successfully marked as published." \ | ||
% message_bit) | ||
|
||
make_published.short_description = "Mark selected stories as published" | ||
|
||
|
||
admin.site.register(Author, AuthorAdmin) | ||
admin.site.register(Article, ArticleAdmin) |
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,20 @@ | ||
from django.db import models | ||
|
||
STATUS_CHOICES = ( | ||
('d', 'Draft'), | ||
('p', 'Published'), | ||
('w', 'Withdrawn'), | ||
) | ||
|
||
class Article(models.Model): | ||
title = models.CharField(max_length=100) | ||
body = models.TextField() | ||
status = models.CharField(max_length=1, choices=STATUS_CHOICES) | ||
|
||
def __unicode__(self): | ||
return self.title | ||
|
||
class Author(models.Model): | ||
name = models.CharField(max_length=100) | ||
title = models.CharField(max_length=3) | ||
birth_date = models.DateField(blank=True, null=True) |
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 @@ | ||
""" | ||
This file demonstrates writing tests using the unittest module. These will pass | ||
when you run "manage.py test". | ||
Replace this with more appropriate tests for your application. | ||
""" | ||
|
||
from django.test import TestCase | ||
|
||
|
||
class SimpleTest(TestCase): | ||
def test_basic_addition(self): | ||
""" | ||
Tests that 1 + 1 always equals 2. | ||
""" | ||
self.assertEqual(1 + 1, 2) |
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 @@ | ||
# Create your views here. |