af Kenny Belitzky 16 år siden
7250
Mere som dette
If this view is fetched with GET, it will display a confirmation page (i.e. “do you really want to delete this object?”). If the view is submitted with POST, the object will be deleted without confirmation.
object
w/r/t template_object_name
form (FormWrapper instance)
commonargs (5)
from django.conf.urls.defaults import *
from django.views.generic import list_detail, date_based, create_update
from bookstore.models import Publisher, Author, Book
book_info = {
"queryset" : Book.objects.all(),
"date_field" : "publication_date",
}
urlpatterns = patterns('',
(r'^books/edit/(?P
FormWrapper example
form (FormWrapper instance)
commonargs (4)
mimetype (?)
login_required
default = False
post_save_redirect
• post_save_redirect may contain dictionary string formatting, which will be interpolated against the object's field attributes. For example, you could use post_save_redirect="/polls/%(slug)s/".
default = object.get_absolute_url()
model
from django.conf.urls.defaults import * from django.views.generic import list_detail, date_based, create_update from bookstore.models import Publisher, Author, Book book_info = { "queryset" : Book.objects.all(), "date_field" : "publication_date", } urlpatterns = patterns('', (r'^books/create/$', create_update.create_object, {'model' : Book}), )
Note that these views all have a very rough idea of security. Although they take a login_required attribute which if given will restrict access to logged-in users, that’s as far as it goes. They won’t, for example, check that the user editing an object is the same user that created it, nor will they validate any sort of permissions. Much of the time, however, those features can be accomplished by writing a small wrapper around the generic view; see “extending generic views”, below, for more about this topic.
object (w/r/t template_object_name parameter)
week (datetime.date object)
from django.conf.urls.defaults import *
from django.views.generic import list_detail, date_based, create_update
from bookstore.models import Publisher, Author, Book
book_info = {
"queryset" : Book.objects.all(),
"date_field" : "publication_date",
}
urlpatterns = patterns('',
(r'^(?P
as archive_day.
previous_day
next_day
day_format
default = "%d" (decimal 01-31)
day
from django.conf.urls.defaults import *
from django.views.generic import list_detail, date_based, create_update
from bookstore.models import Publisher, Author, Book
book_info = {
"queryset" : Book.objects.all(),
"date_field" : "publication_date",
}
urlpatterns = patterns('',
(r'^(?P
week (datetime.date object)
week
from django.conf.urls.defaults import *
from django.views.generic import list_detail, date_based, create_update
from bookstore.models import Publisher, Author, Book
book_info = {
"queryset" : Book.objects.all(),
"date_field" : "publication_date",
}
urlpatterns = patterns('',
(r'^(?P
previous_month
next_month
month (datetime.date object)
month_format
default = "%b", e.g., "jan", "feb", etc. re: time.strftime. "%m" is numbers.
month
from django.conf.urls.defaults import *
from django.views.generic import list_detail, date_based, create_update
from bookstore.models import Publisher, Author, Book
book_info = {
"queryset" : Book.objects.all(),
"date_field" : "publication_date",
}
urlpatterns = patterns('',
(r'^(?P
make_object_list
default = False (whether to retrieve full year list of objects)
year
from django.conf.urls.defaults import *
from django.views.generic import list_detail, date_based, create_update
from bookstore.models import Publisher, Author, Book
book_info = {
"queryset" : Book.objects.all(),
"date_field" : "publication_date",
}
urlpatterns = patterns('',
(r'^books/(?P
latest
date_list (list of datetime.date objects)
template_object_name (?)
num_latest
default = 15
allow_future
default = False (allows publication of post-dated objects)
date_field
from django.conf.urls.defaults import * from django.views.generic import list_detail, date_based, create_update from bookstore.models import Publisher, Author, Book book_info = { "queryset" : Book.objects.all(), "date_field" : "publication_date", } urlpatterns = patterns('', (r'^books/$', date_based.archive_index, book_info), )
'object'
default name = 'object', e.g., override with template_object_name = 'foo', then object name will be 'foo'.
allow_empty (?)
template_name_field
fieldname whose value names the template to use, i.e., 'the_template' --> 'foo.html' --> generic view using foo.html.
or
slug + slug_field
object_id
from django.conf.urls.defaults import *
from django.views.generic import list_detail, date_based, create_update
from bookstore.models import Publisher, Author, Book
author_detail_info = {
"queryset" : Author.objects.all(),
"template_object_name" : "author",
}
urlpatterns = patterns('',
(r'^authors/(?P
is_paginated
hits
pages
previous
next
page
has_previous
has_next
results_per_page
using page string paramater (GET), or page variable (URLconf)
/objects/?page=3
author_detail_info = {
"queryset" : Author.objects.all(),
"template_object_name" : "author",
}
urlpatterns = patterns('',
(r'^objects/page(?P
object_list
template_object_name
template_name
template_loader
mimetype
extra_context
context_processors
allow_empty
paginate_by
queryset
from django.conf.urls.defaults import * from django.views.generic import list_detail, date_based, create_update from bookstore.models import Publisher, Author, Book author_list_info = { 'queryset' : Author.objects.all(), 'allow_empty': True, } urlpatterns = patterns('', (r'authors/$', list_detail.object_list, author_list_info), )