mirror of
https://github.com/django/django.git
synced 2024-12-27 03:25:58 +00:00
ab8965c428
Python 2.3 compatibility. Patch from nfg. Refs #8151, #8153. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8236 bcc190cf-cafb-0310-a4f2-bffc1f526a37
66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
from django.db import models
|
|
from django.contrib import admin
|
|
|
|
class Section(models.Model):
|
|
"""
|
|
A simple section that links to articles, to test linking to related items
|
|
in admin views.
|
|
"""
|
|
name = models.CharField(max_length=100)
|
|
|
|
class Article(models.Model):
|
|
"""
|
|
A simple article to test admin views. Test backwards compatibility.
|
|
"""
|
|
title = models.CharField(max_length=100)
|
|
content = models.TextField()
|
|
date = models.DateTimeField()
|
|
section = models.ForeignKey(Section)
|
|
|
|
def __unicode__(self):
|
|
return self.title
|
|
|
|
class ArticleAdmin(admin.ModelAdmin):
|
|
list_display = ('content', 'date')
|
|
list_filter = ('date',)
|
|
|
|
def changelist_view(self, request):
|
|
"Test that extra_context works"
|
|
return super(ArticleAdmin, self).changelist_view(
|
|
request, extra_context={
|
|
'extra_var': 'Hello!'
|
|
}
|
|
)
|
|
|
|
class CustomArticle(models.Model):
|
|
content = models.TextField()
|
|
date = models.DateTimeField()
|
|
|
|
class CustomArticleAdmin(admin.ModelAdmin):
|
|
"""
|
|
Tests various hooks for using custom templates and contexts.
|
|
"""
|
|
change_list_template = 'custom_admin/change_list.html'
|
|
change_form_template = 'custom_admin/change_form.html'
|
|
object_history_template = 'custom_admin/object_history.html'
|
|
delete_confirmation_template = 'custom_admin/delete_confirmation.html'
|
|
|
|
def changelist_view(self, request):
|
|
"Test that extra_context works"
|
|
return super(CustomArticleAdmin, self).changelist_view(
|
|
request, extra_context={
|
|
'extra_var': 'Hello!'
|
|
}
|
|
)
|
|
|
|
class ModelWithStringPrimaryKey(models.Model):
|
|
id = models.CharField(max_length=255, primary_key=True)
|
|
|
|
def __unicode__(self):
|
|
return self.id
|
|
|
|
admin.site.register(Article, ArticleAdmin)
|
|
admin.site.register(CustomArticle, CustomArticleAdmin)
|
|
admin.site.register(Section)
|
|
admin.site.register(ModelWithStringPrimaryKey)
|