mirror of
https://github.com/django/django.git
synced 2025-07-05 18:29:11 +00:00
merged r741:748 into new-admin
git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@749 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e6c080db2b
commit
3afc81d44e
@ -7,7 +7,7 @@ from django.conf.settings import LANGUAGE_CODE, SETTINGS_MODULE
|
|||||||
|
|
||||||
class FeedConfiguration:
|
class FeedConfiguration:
|
||||||
def __init__(self, slug, title_cb, link_cb, description_cb, get_list_func_cb, get_list_kwargs,
|
def __init__(self, slug, title_cb, link_cb, description_cb, get_list_func_cb, get_list_kwargs,
|
||||||
param_func=None, param_kwargs_cb=None, get_list_kwargs_cb=None,
|
param_func=None, param_kwargs_cb=None, get_list_kwargs_cb=None, get_pubdate_cb=None,
|
||||||
enc_url=None, enc_length=None, enc_mime_type=None):
|
enc_url=None, enc_length=None, enc_mime_type=None):
|
||||||
"""
|
"""
|
||||||
slug -- Normal Python string. Used to register the feed.
|
slug -- Normal Python string. Used to register the feed.
|
||||||
@ -28,6 +28,9 @@ class FeedConfiguration:
|
|||||||
|
|
||||||
get_list_kwargs_cb -- Function that takes the param and returns a
|
get_list_kwargs_cb -- Function that takes the param and returns a
|
||||||
dictionary to use in addition to get_list_kwargs (if applicable).
|
dictionary to use in addition to get_list_kwargs (if applicable).
|
||||||
|
|
||||||
|
get_pubdate_cb -- Function that takes the object and returns a datetime
|
||||||
|
to use as the publication date in the feed.
|
||||||
|
|
||||||
The three enc_* parameters are strings representing methods or
|
The three enc_* parameters are strings representing methods or
|
||||||
attributes to call on a particular item to get its enclosure
|
attributes to call on a particular item to get its enclosure
|
||||||
@ -41,6 +44,7 @@ class FeedConfiguration:
|
|||||||
self.get_list_kwargs = get_list_kwargs
|
self.get_list_kwargs = get_list_kwargs
|
||||||
self.param_func, self.param_kwargs_cb = param_func, param_kwargs_cb
|
self.param_func, self.param_kwargs_cb = param_func, param_kwargs_cb
|
||||||
self.get_list_kwargs_cb = get_list_kwargs_cb
|
self.get_list_kwargs_cb = get_list_kwargs_cb
|
||||||
|
self.get_pubdate_cb = get_pubdate_cb
|
||||||
assert (None == enc_url == enc_length == enc_mime_type) or (enc_url is not None and enc_length is not None and enc_mime_type is not None)
|
assert (None == enc_url == enc_length == enc_mime_type) or (enc_url is not None and enc_length is not None and enc_mime_type is not None)
|
||||||
self.enc_url = enc_url
|
self.enc_url = enc_url
|
||||||
self.enc_length = enc_length
|
self.enc_length = enc_length
|
||||||
@ -95,6 +99,7 @@ class FeedConfiguration:
|
|||||||
description = description_template.render(Context({'obj': obj, 'site': current_site})).decode('utf-8'),
|
description = description_template.render(Context({'obj': obj, 'site': current_site})).decode('utf-8'),
|
||||||
unique_id=link,
|
unique_id=link,
|
||||||
enclosure=enc,
|
enclosure=enc,
|
||||||
|
pubdate = self.get_pubdate_cb and self.get_pubdate_cb(obj) or None,
|
||||||
)
|
)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
@ -524,7 +524,7 @@ model with an ``ImageField`` will also get this method.
|
|||||||
get_FOO_url()
|
get_FOO_url()
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
For every ``FileField``, the object will have a ``get_FOO_filename()`` method,
|
For every ``FileField``, the object will have a ``get_FOO_url()`` method,
|
||||||
where ``FOO`` is the name of the field. This returns the full URL to the file,
|
where ``FOO`` is the name of the field. This returns the full URL to the file,
|
||||||
according to your ``MEDIA_URL`` setting. If the value is blank, this method
|
according to your ``MEDIA_URL`` setting. If the value is blank, this method
|
||||||
returns an empty string.
|
returns an empty string.
|
||||||
|
@ -248,7 +248,28 @@ Here are all available field types:
|
|||||||
uploaded files don't fill up the given directory).
|
uploaded files don't fill up the given directory).
|
||||||
|
|
||||||
The admin represents this as an ``<input type="file">`` (a file-upload widget).
|
The admin represents this as an ``<input type="file">`` (a file-upload widget).
|
||||||
|
|
||||||
|
Using a `FieldField` or an ``ImageField`` (see below) in a model takes a few
|
||||||
|
steps:
|
||||||
|
|
||||||
|
1. In your settings file, you'll need to define ``MEDIA_ROOT``as the
|
||||||
|
full path to a directory where you'd like Django to store uploaded
|
||||||
|
files. (For performance, these files are not stored in the database.)
|
||||||
|
Define ``MEDIA_URL`` as the base public URL of that directory. Make
|
||||||
|
sure that this directory is writable by the Web server's user
|
||||||
|
account.
|
||||||
|
|
||||||
|
2. Add the ``FileField`` or ``ImageField`` to your model, making sure
|
||||||
|
to define the ``upload_to`` option to tell Django to which
|
||||||
|
subdirectory of ``MEDIA_ROOT`` it should upload files.
|
||||||
|
|
||||||
|
3. All that will be stored in your database is a path to the file
|
||||||
|
(relative to ``MEDIA_ROOT``). You'll must likely want to use the
|
||||||
|
convenience ``get_<fieldname>_url`` function provided by Django. For
|
||||||
|
example, if your ``ImageField`` is called ``mug_shot``, you can get
|
||||||
|
the absolute URL to your image in a template with ``{{
|
||||||
|
object.get_mug_shot_url }}``.
|
||||||
|
|
||||||
.. _`strftime formatting`: http://docs.python.org/lib/module-time.html#l2h-1941
|
.. _`strftime formatting`: http://docs.python.org/lib/module-time.html#l2h-1941
|
||||||
|
|
||||||
``FloatField``
|
``FloatField``
|
||||||
@ -281,7 +302,7 @@ Here are all available field types:
|
|||||||
width of the image each time a model instance is saved.
|
width of the image each time a model instance is saved.
|
||||||
|
|
||||||
Requires the `Python Imaging Library`_.
|
Requires the `Python Imaging Library`_.
|
||||||
|
|
||||||
.. _Python Imaging Library: http://www.pythonware.com/products/pil/
|
.. _Python Imaging Library: http://www.pythonware.com/products/pil/
|
||||||
|
|
||||||
``IntegerField``
|
``IntegerField``
|
||||||
|
@ -385,23 +385,23 @@ Let's jump back into the Python interactive shell::
|
|||||||
# Django provides a rich database lookup API that's entirely driven by
|
# Django provides a rich database lookup API that's entirely driven by
|
||||||
# keyword arguments.
|
# keyword arguments.
|
||||||
>>> polls.get_object(id__exact=1)
|
>>> polls.get_object(id__exact=1)
|
||||||
What's up
|
What's up?
|
||||||
>>> polls.get_object(question__startswith='What')
|
>>> polls.get_object(question__startswith='What')
|
||||||
What's up
|
What's up?
|
||||||
>>> polls.get_object(pub_date__year=2005)
|
>>> polls.get_object(pub_date__year=2005)
|
||||||
What's up
|
What's up?
|
||||||
>>> polls.get_object(id__exact=2)
|
>>> polls.get_object(id__exact=2)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
PollDoesNotExist: Poll does not exist for {'id__exact': 2}
|
PollDoesNotExist: Poll does not exist for {'id__exact': 2}
|
||||||
>>> polls.get_list(question__startswith='What')
|
>>> polls.get_list(question__startswith='What')
|
||||||
[What's up]
|
[What's up?]
|
||||||
|
|
||||||
# Lookup by a primary key is the most common case, so Django provides a
|
# Lookup by a primary key is the most common case, so Django provides a
|
||||||
# shortcut for primary-key exact lookups.
|
# shortcut for primary-key exact lookups.
|
||||||
# The following is identical to polls.get_object(id__exact=1).
|
# The following is identical to polls.get_object(id__exact=1).
|
||||||
>>> polls.get_object(pk=1)
|
>>> polls.get_object(pk=1)
|
||||||
What's up
|
What's up?
|
||||||
|
|
||||||
# Make sure our custom method worked.
|
# Make sure our custom method worked.
|
||||||
>>> p = polls.get_object(pk=1)
|
>>> p = polls.get_object(pk=1)
|
||||||
@ -419,7 +419,7 @@ Let's jump back into the Python interactive shell::
|
|||||||
|
|
||||||
# Choice objects have API access to their related Poll objects.
|
# Choice objects have API access to their related Poll objects.
|
||||||
>>> c.get_poll()
|
>>> c.get_poll()
|
||||||
What's up
|
What's up?
|
||||||
|
|
||||||
# And vice versa: Poll objects get access to Choice objects.
|
# And vice versa: Poll objects get access to Choice objects.
|
||||||
>>> p.get_choice_list()
|
>>> p.get_choice_list()
|
||||||
|
@ -91,8 +91,8 @@ Finally, it calls that ``detail()`` function like so::
|
|||||||
detail(request=<HttpRequest object>, poll_id=23)
|
detail(request=<HttpRequest object>, poll_id=23)
|
||||||
|
|
||||||
The ``poll_id=23`` part comes from ``(?P<poll_id>\d+)``. Using
|
The ``poll_id=23`` part comes from ``(?P<poll_id>\d+)``. Using
|
||||||
``(?<name>pattern)`` "captures" the text matched by ``pattern`` and sends it as
|
``(?P<name>pattern)`` "captures" the text matched by ``pattern`` and sends it
|
||||||
a keyword argument to the view function.
|
as a keyword argument to the view function.
|
||||||
|
|
||||||
Because the URL patterns are regular expressions, there really is no limit on
|
Because the URL patterns are regular expressions, there really is no limit on
|
||||||
what you can do with them. And there's no need to add URL cruft such as
|
what you can do with them. And there's no need to add URL cruft such as
|
||||||
|
Loading…
x
Reference in New Issue
Block a user