Changeset 8215 for django/branches/gis/docs
- Timestamp:
- 08/05/08 12:15:33 (4 months ago)
- Files:
-
- django/branches/gis (modified) (1 prop)
- django/branches/gis/docs/add_ons.txt (modified) (2 diffs)
- django/branches/gis/docs/admin.txt (modified) (26 diffs)
- django/branches/gis/docs/api_stability.txt (modified) (3 diffs)
- django/branches/gis/docs/authentication.txt (modified) (5 diffs)
- django/branches/gis/docs/cache.txt (modified) (3 diffs)
- django/branches/gis/docs/contenttypes.txt (modified) (1 diff)
- django/branches/gis/docs/contributing.txt (modified) (1 diff)
- django/branches/gis/docs/csrf.txt (modified) (4 diffs)
- django/branches/gis/docs/custom_model_fields.txt (modified) (8 diffs)
- django/branches/gis/docs/databases.txt (modified) (1 diff)
- django/branches/gis/docs/db-api.txt (modified) (5 diffs)
- django/branches/gis/docs/django-admin.txt (modified) (1 diff)
- django/branches/gis/docs/email.txt (modified) (1 diff)
- django/branches/gis/docs/faq.txt (modified) (2 diffs)
- django/branches/gis/docs/fastcgi.txt (modified) (3 diffs)
- django/branches/gis/docs/form_for_model.txt (modified) (5 diffs)
- django/branches/gis/docs/form_preview.txt (modified) (2 diffs)
- django/branches/gis/docs/forms.txt (copied) (copied from django/trunk/docs/forms.txt)
- django/branches/gis/docs/form_wizard.txt (modified) (7 diffs)
- django/branches/gis/docs/generic_views.txt (modified) (18 diffs)
- django/branches/gis/docs/i18n.txt (modified) (4 diffs)
- django/branches/gis/docs/index.txt (modified) (1 diff)
- django/branches/gis/docs/install.txt (modified) (2 diffs)
- django/branches/gis/docs/localflavor.txt (modified) (10 diffs)
- django/branches/gis/docs/middleware.txt (modified) (1 diff)
- django/branches/gis/docs/model-api.txt (modified) (8 diffs)
- django/branches/gis/docs/modelforms.txt (modified) (8 diffs)
- django/branches/gis/docs/modpython.txt (modified) (3 diffs)
- django/branches/gis/docs/newforms.txt (deleted)
- django/branches/gis/docs/oldforms.txt (copied) (copied from django/trunk/docs/oldforms.txt)
- django/branches/gis/docs/overview.txt (modified) (3 diffs)
- django/branches/gis/docs/pagination.txt (modified) (3 diffs)
- django/branches/gis/docs/release_notes_0.95.txt (modified) (2 diffs)
- django/branches/gis/docs/release_notes_1.0_alpha.txt (copied) (copied from django/trunk/docs/release_notes_1.0_alpha.txt)
- django/branches/gis/docs/request_response.txt (modified) (1 diff)
- django/branches/gis/docs/serialization.txt (modified) (4 diffs)
- django/branches/gis/docs/sessions.txt (modified) (1 diff)
- django/branches/gis/docs/settings.txt (modified) (3 diffs)
- django/branches/gis/docs/sitemaps.txt (modified) (1 diff)
- django/branches/gis/docs/templates.txt (modified) (5 diffs)
- django/branches/gis/docs/testing.txt (modified) (4 diffs)
- django/branches/gis/docs/tutorial02.txt (modified) (3 diffs)
- django/branches/gis/docs/tutorial03.txt (modified) (1 diff)
- django/branches/gis/docs/upload_handling.txt (modified) (4 diffs)
- django/branches/gis/docs/url_dispatch.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis
- Property svnmerge-integrated changed from /django/trunk:1-7978 to /django/trunk:1-8214
django/branches/gis/docs/add_ons.txt
r7354 r8215 24 24 25 25 The automatic Django administrative interface. For more information, see 26 `Tutorial 2`_ .26 `Tutorial 2`_ and the `admin documentation`_. 27 27 28 28 .. _Tutorial 2: ../tutorial02/ 29 .. _admin documentation: ../admin/ 29 30 30 31 Requires the auth_ and contenttypes_ contrib packages to be installed. … … 77 78 ========= 78 79 79 A set of high-level abstractions for Django forms (django. newforms).80 A set of high-level abstractions for Django forms (django.forms). 80 81 81 82 django.contrib.formtools.preview django/branches/gis/docs/admin.txt
r7979 r8215 19 19 ======== 20 20 21 There are four steps in activating the Django admin site: 22 23 1. Determine which of your application's models should be editable in the 21 There are five steps in activating the Django admin site: 22 23 1. Add ``django.contrib.admin`` to your ``INSTALLED_APPS`` setting. 24 25 2. Determine which of your application's models should be editable in the 24 26 admin interface. 25 27 26 2. For each of those models, optionally create a ``ModelAdmin`` class that28 3. For each of those models, optionally create a ``ModelAdmin`` class that 27 29 encapsulates the customized admin functionality and options for that 28 30 particular model. 29 31 30 3. Instantiate an ``AdminSite`` and tell it about each of your models and32 4. Instantiate an ``AdminSite`` and tell it about each of your models and 31 33 ``ModelAdmin`` classes. 32 34 33 4. Hook the ``AdminSite`` instance into your URLconf.35 5. Hook the ``AdminSite`` instance into your URLconf. 34 36 35 37 ``ModelAdmin`` objects … … 42 44 from django.contrib import admin 43 45 from myproject.myapp.models import Author 44 46 45 47 class AuthorAdmin(admin.ModelAdmin): 46 48 pass … … 67 69 68 70 date_hierarchy = 'pub_date' 71 72 ``form`` 73 ~~~~~~~~ 74 75 The default ``forms.ModelForm`` class used to generate the form on the 76 add/change pages for models. You can easily change this to your own 77 ``ModelForm`` to override the default form behavior of the add/change pages. 69 78 70 79 ``fieldsets`` … … 83 92 84 93 A full example, taken from the ``django.contrib.flatpages.FlatPage`` model:: 85 94 86 95 class FlatPageAdmin(admin.ModelAdmin): 87 96 fieldsets = ( … … 107 116 ``fields`` 108 117 A tuple of field names to display in this fieldset. This key is required. 109 118 110 119 Example:: 111 120 112 121 { 113 122 'fields': ('first_name', 'last_name', 'address', 'city', 'state'), … … 117 126 tuple. In this example, the ``first_name`` and ``last_name`` fields will 118 127 display on the same line:: 119 128 120 129 { 121 130 'fields': (('first_name', 'last_name'), 'address', 'city', 'state'), … … 123 132 124 133 ``classes`` 125 A stringcontaining extra CSS classes to apply to the fieldset.126 134 A list containing extra CSS classes to apply to the fieldset. 135 127 136 Example:: 128 137 129 138 { 130 'classes': 'wide',139 'classes': ['wide', 'extrapretty'], 131 140 } 132 141 133 Apply multiple classes by separating them with spaces. Example::134 135 {136 'classes': 'wide extrapretty',137 }138 139 142 Two useful classes defined by the default admin-site stylesheet are 140 143 ``collapse`` and ``wide``. Fieldsets with the ``collapse`` style will be … … 144 147 ``description`` 145 148 A string of optional extra text to be displayed at the top of each fieldset, 146 under the heading of the fieldset. It's used verbatim, so you can use any HTML 147 and you must escape any special HTML characters (such as ampersands) yourself. 149 under the heading of the fieldset. 150 151 Note that this value is *not* HTML-escaped when it's displayed in 152 the admin interface. This lets you include HTML if you so desire. 153 Alternatively you can use plain text and 154 ``django.utils.html.escape()`` to escape any HTML special 155 characters. 156 157 ``fields`` 158 ~~~~~~~~~~ 159 160 Use this option as an alternative to ``fieldsets`` if the layout does not 161 matter and if you want to only show a subset of the available fields in the 162 form. For example, you could define a simpler version of the admin form for 163 the ``django.contrib.flatpages.FlatPage`` model as follows:: 164 165 class FlatPageAdmin(admin.ModelAdmin): 166 fields = ('url', 'title', 'content') 167 168 In the above example, only the fields 'url', 'title' and 'content' will be 169 displayed, sequencially, in the form. 170 171 .. admonition:: Note 172 173 This ``fields`` option should not be confused with the ``fields`` 174 dictionary key that is within the ``fieldsets`` option, as described in 175 the previous section. 148 176 149 177 ``filter_horizontal`` 150 178 ~~~~~~~~~~~~~~~~~~~~~ 151 179 152 Use a nifty unobtrusive Java script "filter" interface instead of the180 Use a nifty unobtrusive JavaScript "filter" interface instead of the 153 181 usability-challenged ``<select multiple>`` in the admin form. The value is a 154 182 list of fields that should be displayed as a horizontal filter interface. See … … 193 221 194 222 Here's a full example model:: 195 223 196 224 class Person(models.Model): 197 225 name = models.CharField(max_length=50) … … 201 229 return self.birthday.strftime('%Y')[:3] + "0's" 202 230 decade_born_in.short_description = 'Birth decade' 203 231 204 232 class PersonAdmin(admin.ModelAdmin): 205 233 list_display = ('name', 'decade_born_in') … … 219 247 return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name) 220 248 colored_name.allow_tags = True 221 249 222 250 class PersonAdmin(admin.ModelAdmin): 223 251 list_display = ('first_name', 'last_name', 'colored_name') … … 236 264 return self.birthday.strftime('%Y')[:3] == 5 237 265 born_in_fifties.boolean = True 238 266 239 267 class PersonAdmin(admin.ModelAdmin): 240 268 list_display = ('name', 'born_in_fifties') … … 265 293 colored_first_name.allow_tags = True 266 294 colored_first_name.admin_order_field = 'first_name' 267 295 268 296 class PersonAdmin(admin.ModelAdmin): 269 297 list_display = ('first_name', 'colored_first_name') … … 356 384 If this isn't provided, the Django admin will use the model's default ordering. 357 385 386 .. admonition:: Note 387 388 Django will only honor the first element in the list/tuple; any others 389 will be ignored. 390 358 391 ``prepopulated_fields`` 359 392 ~~~~~~~~~~~~~~~~~~~~~~~ … … 365 398 prepopulated_fields = {"slug": ("title",)} 366 399 367 When set the given fields will use a bit of Javascript to populate from the 368 fields assigned. 369 370 ``prepopulated_fields`` doesn't accept DateTimeFields, ForeignKeys nor 371 ManyToManyFields. 400 When set, the given fields will use a bit of JavaScript to populate from the 401 fields assigned. The main use for this functionality is to automatically 402 generate the value for ``SlugField`` fields from one or more other fields. The 403 generated value is produced by concatenating the values of the source fields, 404 and then by transforming that result into a valid slug (e.g. substituting 405 dashes for spaces). 406 407 ``prepopulated_fields`` doesn't accept ``DateTimeField``, ``ForeignKey``, nor 408 ``ManyToManyField`` fields. 372 409 373 410 ``radio_fields`` … … 397 434 398 435 ``raw_id_fields`` is a list of fields you would like to change 399 into a ``Input`` widget for the primary key. 436 into a ``Input`` widget for either a ``ForeignKey`` or ``ManyToManyField``:: 437 438 class ArticleAdmin(admin.ModelAdmin): 439 raw_id_fields = ("newspaper",) 400 440 401 441 ``save_as`` … … 485 525 -------------------------------- 486 526 487 There are times where you would like add a bit of CSS and/or Java script to527 There are times where you would like add a bit of CSS and/or JavaScript to 488 528 the add/change views. This can be accomplished by using a Media inner class 489 529 on your ``ModelAdmin``:: … … 499 539 apply as `regular media definitions on forms`_. 500 540 501 .. _regular media definitions on forms: ../newforms/#media 541 .. _regular media definitions on forms: ../forms/#media 542 543 Adding custom validation to the admin 544 ------------------------------------- 545 546 Adding custom validation of data in the admin is quite easy. The automatic 547 admin interfaces reuses the Django `forms`_ module. The ``ModelAdmin`` class 548 gives you the ability define your own form:: 549 550 class ArticleAdmin(admin.ModelAdmin): 551 form = MyArticleAdminForm 552 553 ``MyArticleAdminForm`` can be defined anywhere as long as you import where 554 needed. Now within your form you can add your own custom validation for 555 any field:: 556 557 class MyArticleAdminForm(forms.ModelForm): 558 def clean_name(self): 559 # do something that validates your data 560 return self.cleaned_data["name"] 561 562 It is important you use a ``ModelForm`` here otherwise things can break. See 563 the `forms`_ documentation on `custom validation`_ for more information. 564 565 .. _forms: ../forms/ 566 .. _custom validation: ../forms/#custom-form-and-field-validation 502 567 503 568 ``InlineModelAdmin`` objects … … 505 570 506 571 The admin interface has the ability to edit models on the same page as a 507 parent model. These are called inlines. You can add them a model being508 specif ing them in a ``ModelAdmin.inlines`` attribute::572 parent model. These are called inlines. You can add them to a model by 573 specifying them in a ``ModelAdmin.inlines`` attribute:: 509 574 510 575 class BookInline(admin.TabularInline): 511 576 model = Book 512 577 513 578 class AuthorAdmin(admin.ModelAdmin): 514 579 inlines = [ … … 516 581 ] 517 582 518 Django provides two subclasses of ``InlineModelAdmin`` and they are: :583 Django provides two subclasses of ``InlineModelAdmin`` and they are: 519 584 520 585 * ``TabularInline`` … … 563 628 to the initial forms. See the `formsets documentation`_ for more information. 564 629 565 .. _formsets documentation: ../ newforms/#formsets630 .. _formsets documentation: ../forms/#formsets 566 631 567 632 ``max_num`` … … 574 639 .. _max_num in formsets: ../modelforms/#limiting-the-number-of-objects-editable 575 640 641 ``raw_id_fields`` 642 ~~~~~~~~~~~~~~~~~ 643 644 By default, Django's admin uses a select-box interface (<select>) for 645 fields that are ``ForeignKey``. Sometimes you don't want to incur the 646 overhead of having to select all the related instances to display in the 647 drop-down. 648 649 ``raw_id_fields`` is a list of fields you would like to change 650 into a ``Input`` widget for either a ``ForeignKey`` or ``ManyToManyField``:: 651 652 class BookInline(admin.TabularInline): 653 model = Book 654 raw_id_fields = ("pages",) 655 576 656 ``template`` 577 657 ~~~~~~~~~~~~ … … 599 679 to_person = models.ForeignKey(Person, related_name="friends") 600 680 from_person = models.ForeignKey(Person, related_name="from_friends") 601 681 602 682 If you wanted to display an inline on the ``Person`` admin add/change pages 603 683 you need to explicitly define the foreign key since it is unable to do so … … 607 687 model = Friendship 608 688 fk_name = "to_person" 609 689 610 690 class PersonAdmin(admin.ModelAdmin): 611 691 inlines = [ … … 613 693 ] 614 694 695 Working with Many-to-Many Intermediary Models 696 ---------------------------------------------- 697 698 By default, admin widgets for many-to-many relations will be displayed inline 699 on whichever model contains the actual reference to the ``ManyToManyField``. 700 However, when you specify an intermediary model using the ``through`` 701 argument to a ``ManyToManyField``, the admin will not display a widget by 702 default. This is because each instance of that intermediary model requires 703 more information than could be displayed in a single widget, and the layout 704 required for multiple widgets will vary depending on the intermediate model. 705 706 However, we still want to be able to edit that information inline. Fortunately, 707 this is easy to do with inline admin models. Suppose we have the following 708 models:: 709 710 class Person(models.Model): 711 name = models.CharField(max_length=128) 712 713 class Group(models.Model): 714 name = models.CharField(max_length=128) 715 members = models.ManyToManyField(Person, through='Membership') 716 717 class Membership(models.Model): 718 person = models.ForeignKey(Person) 719 group = models.ForeignKey(Group) 720 date_joined = models.DateField() 721 invite_reason = models.CharField(max_length=64) 722 723 The first step in displaying this intermediate model in the admin is to 724 define an inline class for the ``Membership`` model:: 725 726 class MembershipInline(admin.TabularInline): 727 model = Membership 728 extra = 1 729 730 This simple example uses the default ``InlineModelAdmin`` values for the 731 ``Membership`` model, and limits the extra add forms to one. This could be 732 customized using any of the options available to ``InlineModelAdmin`` classes. 733 734 Now create admin views for the ``Person`` and ``Group`` models:: 735 736 class PersonAdmin(admin.ModelAdmin): 737 inlines = (MembershipInline,) 738 739 class GroupAdmin(admin.ModelAdmin): 740 inlines = (MembershipInline,) 741 742 Finally, register your ``Person`` and ``Group`` models with the admin site:: 743 744 admin.site.register(Person, PersonAdmin) 745 admin.site.register(Group, GroupAdmin) 746 747 Now your admin site is set up to edit ``Membership`` objects inline from 748 either the ``Person`` or the ``Group`` detail pages. 749 615 750 ``AdminSite`` objects 616 751 ===================== … … 629 764 from django.conf.urls.defaults import * 630 765 from django.contrib import admin 631 766 632 767 admin.autodiscover() 633 768 django/branches/gis/docs/api_stability.txt
r7354 r8215 60 60 - `Request/response objects`_. 61 61 62 - `Sending e mail`_.62 - `Sending e-mail`_. 63 63 64 64 - `Sessions`_. … … 109 109 .. _redirects: ../redirects/ 110 110 .. _request/response objects: ../request_response/ 111 .. _sending e mail: ../email/111 .. _sending e-mail: ../email/ 112 112 .. _sessions: ../sessions/ 113 113 .. _settings: ../settings/ … … 116 116 .. _transactions: ../transactions/ 117 117 .. _url dispatch: ../url_dispatch/ 118 .. _forms and validation: ../forms/119 118 .. _serialization: ../serialization/ 120 119 .. _authentication: ../authentication/ django/branches/gis/docs/authentication.txt
r7979 r8215 518 518 519 519 * ``form``: A ``Form`` object representing the login form. See the 520 ` newforms documentation`_ for more on ``Form`` objects.520 `forms documentation`_ for more on ``FormWrapper`` objects. 521 521 * ``next``: The URL to redirect to after successful login. This may contain 522 522 a query string, too. … … 558 558 {% endblock %} 559 559 560 .. _ newforms documentation: ../newforms/560 .. _forms documentation: ../forms/ 561 561 .. _site framework docs: ../sites/ 562 562 … … 632 632 633 633 Allows a user to reset their password, and sends them the new password 634 in an e mail.634 in an e-mail. 635 635 636 636 **Optional arguments:** … … 641 641 642 642 * ``email_template_name``: The full name of a template to use for 643 generating the e mail with the new password. This will default to643 generating the e-mail with the new password. This will default to 644 644 ``registration/password_reset_email.html`` if not supplied. 645 645 … … 697 697 698 698 * ``django.contrib.auth.forms.PasswordResetForm``: A form for resetting a 699 user's password and e mailing the new password to them.699 user's password and e-mailing the new password to them. 700 700 701 701 * ``django.contrib.auth.forms.UserCreationForm``: A form for creating a django/branches/gis/docs/cache.txt
r7768 r8215 7 7 from database queries to template rendering to business logic -- to create the 8 8 page that your site's visitor sees. This is a lot more expensive, from a 9 processing-overhead perspective, than your standard read-a-file-off-the-filesystem10 server arrangement.9 processing-overhead perspective, than your standard 10 read-a-file-off-the-filesystem server arrangement. 11 11 12 12 For most Web applications, this overhead isn't a big deal. Most Web … … 160 160 CACHE_BACKEND = 'locmem:///' 161 161 162 Simple caching (for development)163 --------------------------------164 165 A simple, single-process memory cache is available as ``"simple:///"``. This166 merely saves cached data in-process, which means it should only be used in167 development or testing environments. For example::168 169 CACHE_BACKEND = 'simple:///'170 171 **New in Django development version:** This cache backend is deprecated and172 will be removed in a future release. New code should use the ``locmem`` backend173 instead.174 175 162 Dummy caching (for development) 176 163 ------------------------------- … … 186 173 187 174 CACHE_BACKEND = 'dummy:///' 175 176 Using a custom cache backend 177 ---------------------------- 178 179 **New in Django development version** 180 181 While Django includes support for a number of cache backends out-of-the-box, 182 sometimes you will want to use a customised verison or your own backend. To 183 use an external cache backend with Django, use a Python import path as the 184 scheme portion (the part before the initial colon) of the ``CACHE_BACKEND`` 185 URI, like so:: 186 187 CACHE_BACKEND = 'path.to.backend://' 188 189 If you're building your own backend, you can use the standard cache backends 190 as reference implementations. You'll find the code in the 191 ``django/core/cache/backends/`` directory of the Django source. 192 193 Note: Without a really compelling reason, like a host that doesn't support the 194 them, you should stick to the cache backends included with Django. They've 195 been really well-tested and are quite easy to use. 188 196 189 197 CACHE_BACKEND arguments django/branches/gis/docs/contenttypes.txt
r7979 r8215 206 206 ``IntegerField`` or ``PositiveIntegerField``.) 207 207 208 This field must be of the same type as the primary key of the models209 that will be involved in the generic relation. For example, if you use210 ``IntegerField``, you won't be able to form a generic relation with a211 model that uses a ``CharField`` as a primary key.208 This field must be of the same type as the primary key of the models 209 that will be involved in the generic relation. For example, if you use 210 ``IntegerField``, you won't be able to form a generic relation with a 211 model that uses a ``CharField`` as a primary key. 212 212 213 213 3. Give your model a ``GenericForeignKey``, and pass it the names of django/branches/gis/docs/contributing.txt
r7918 r8215 526 526 * All database fields 527 527 * ``class Meta`` 528 * ``class Admin``529 528 * ``def __unicode__()`` 530 529 * ``def __str__()`` django/branches/gis/docs/csrf.txt
r7354 r8215 5 5 The CsrfMiddleware class provides easy-to-use protection against 6 6 `Cross Site Request Forgeries`_. This type of attack occurs when a malicious 7 web site creates a link or form button that is intended to perform some action8 on your web site, using the credentials of a logged-in user who is tricked7 Web site creates a link or form button that is intended to perform some action 8 on your Web site, using the credentials of a logged-in user who is tricked 9 9 into clicking on the link in their browser. 10 10 … … 39 39 isn't, the user will get a 403 error. 40 40 41 This ensures that only forms that have originated from your web site41 This ensures that only forms that have originated from your Web site 42 42 can be used to POST data back. 43 43 … … 48 48 49 49 POST requests that are not accompanied by a session cookie are not protected, 50 but they do not need to be protected, since the 'attacking' web site50 but they do not need to be protected, since the 'attacking' Web site 51 51 could make these kind of requests anyway. 52 52 … … 65 65 66 66 If your app creates HTML pages and forms in some unusual way, (e.g. 67 it sends fragments of HTML in javascript document.write statements)67 it sends fragments of HTML in JavaScript document.write statements) 68 68 you might bypass the filter that adds the hidden field to the form, 69 69 in which case form submission will always fail. It may still be possible django/branches/gis/docs/custom_model_fields.txt
r7979 r8215 112 112 of the class behavior. 113 113 114 .. _form fields: ../ newforms/#fields114 .. _form fields: ../forms/#fields 115 115 116 116 It's important to realize that a Django field class is not what is stored in … … 386 386 mentioned earlier. Otherwise ``to_python()`` won't be called automatically. 387 387 388 ``get_db_prep_ save(self, value)``389 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 388 ``get_db_prep_value(self, value)`` 389 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 390 390 391 391 This is the reverse of ``to_python()`` when working with the database backends … … 400 400 # ... 401 401 402 def get_db_prep_ save(self, value):402 def get_db_prep_value(self, value): 403 403 return ''.join([''.join(l) for l in (value.north, 404 404 value.east, value.south, value.west)]) 405 406 ``get_db_prep_save(self, value)`` 407 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 408 409 Same as the above, but called when the Field value must be *saved* to the 410 database. As the default implementation just calls ``get_db_prep_value``, you 411 shouldn't need to implement this method unless your custom field need a special 412 conversion when being saved that is not the same as the used for normal query 413 parameters (which is implemented by ``get_db_prep_value``). 414 405 415 406 416 ``pre_save(self, model_instance, add)`` … … 441 451 442 452 If you needed to implement ``get_db_prep_save()``, you will usually need to 443 implement ``get_db_prep_lookup()``. The usual reason is because of the 444 ``range`` and ``in`` lookups. In these case, you will passed a list of 445 objects (presumably of the right type) and will need to convert them to a list 446 of things of the right type for passing to the database. Sometimes you can 447 reuse ``get_db_prep_save()``, or at least factor out some common pieces from 448 both methods into a help function. 449 450 For example:: 453 implement ``get_db_prep_lookup()``. If you don't, ``get_db_prep_value`` will be 454 called by the default implementation, to manage ``exact``, ``gt``, ``gte``, 455 ``lt``, ``lte``, ``in`` and ``range`` lookups. 456 457 You may also want to implement this method to limit the lookup types that could 458 be used with your custom field type. 459 460 Note that, for ``range`` and ``in`` lookups, ``get_db_prep_lookup`` will receive 461 a list of objects (presumably of the right type) and will need to convert them 462 to a list of things of the right type for passing to the database. Most of the 463 time, you can reuse ``get_db_prep_value()``, or at least factor out some common 464 pieces. 465 466 For example, the following code implements ``get_db_prep_lookup`` to limit the 467 accepted lookup types to ``exact`` and ``in``:: 451 468 452 469 class HandField(models.Field): … … 456 473 # We only handle 'exact' and 'in'. All others are errors. 457 474 if lookup_type == 'exact': 458 return self.get_db_prep_ save(value)475 return self.get_db_prep_value(value) 459 476 elif lookup_type == 'in': 460 return [self.get_db_prep_ save(v) for v in value]477 return [self.get_db_prep_value(v) for v in value] 461 478 else: 462 479 raise TypeError('Lookup type %r not supported.' % lookup_type) … … 494 511 fields. 495 512 496 .. _helper functions: ../ newforms/#generating-forms-for-models497 .. _forms documentation: ../ newforms/513 .. _helper functions: ../forms/#generating-forms-for-models 514 .. _forms documentation: ../forms/ 498 515 499 516 ``get_internal_type(self)`` … … 539 556 serialization, the API might change in the future. 540 557 541 Returns a dictionary, mapping the field's attribute name to a flattened string542 version of the data. This method has some internal uses that aren't of 543 interest to use here (mostly having to do with manipulators). For our 544 purposes, it's sufficient to return a one item dictionary that maps the 545 attribute name to a string.558 Returns a dictionary, mapping the field's attribute name to a 559 flattened string version of the data. This method has some internal 560 uses that aren't of interest to use here (mostly having to do with 561 forms). For our purposes, it's sufficient to return a one item 562 dictionary that maps the attribute name to a string. 546 563 547 564 This method is used by the serializers to convert the field into a string for … … 558 575 def flatten_data(self, follow, obj=None): 559 576 value = self._get_val_from_obj(obj) 560 return {self.attname: self.get_db_prep_ save(value)}577 return {self.attname: self.get_db_prep_value(value)} 561 578 562 579 Some general advice django/branches/gis/docs/databases.txt
r7354 r8215 193 193 To run Django's test suite, the user needs these *additional* privileges: 194 194 195 * CREATE DATABASE196 * DROP DATABASE195 * CREATE USER 196 * DROP USER 197 197 * CREATE TABLESPACE 198 198 * DROP TABLESPACE django/branches/gis/docs/db-api.txt
r7918 r8215 464 464 ``extra()`` calls, Django will not inspect these fragments to see if they need 465 465 to be rewritten because of changes in the merged query. So test the effects 466 carefully. Also reali se that if you are combining two ``QuerySets`` with466 carefully. Also realize that if you are combining two ``QuerySets`` with 467 467 ``|``, you cannot use ``extra(select=...)`` or ``extra(where=...)`` on *both* 468 468 ``QuerySets``. You can only use those calls on one or the other (Django will … … 1677 1677 Blog.objects.filter(entry__headline__contains='Lennon') 1678 1678 1679 If you are filtering across multiple relationships and one of the intermediate 1680 models doesn't have a value that meets the filter condition, Django will treat 1681 it as if there is an empty (all values are ``NULL``), but valid, object there. 1682 All this means is that no error will be raised. For example, in this filter:: 1683 1684 Blog.objects.filter(entry__author__name='Lennon') 1685 1686 (if there was a related ``Author`` model), if there was no ``author`` 1687 associated with an entry, it would be treated as if there was also no ``name`` 1688 attached, rather than raising an error because of the missing ``author``. 1689 Usually this is exactly what you want to have happen. The only case where it 1690 might be confusing is if you are using ``isnull``. Thus:: 1691 1692 Blog.objects.filter(entry__author__name__isnull=True) 1693 1694 will return ``Blog`` objects that have an empty ``name`` on the ``author`` and 1695 also those which have an empty ``author`` on the ``entry``. If you don't want 1696 those latter objects, you could write:: 1697 1698 Blog.objetcs.filter(entry__author__isnull=False, 1699 entry__author__name__isnull=True) 1700 1679 1701 Spanning multi-valued relationships 1680 1702 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 2219 2241 every item in a ``QuerySet`` and make sure that the ``save()`` method is 2220 2242 called on each instance, you don't need any special function to handle that. 2221 Just loop over them and call ``save()``: 2243 Just loop over them and call ``save()``:: 2222 2244 2223 2245 for item in my_queryset: … … 2281 2303 to the file, according to your ``MEDIA_ROOT`` setting. 2282 2304 2305 .. note:: 2306 It is only valid to call this method **after** saving the model when the 2307 field has been set. Prior to saving, the value returned will not contain 2308 the upload directory (the `upload_to` parameter) in the path. 2309 2283 2310 Note that ``ImageField`` is technically a subclass of ``FileField``, so every 2284 2311 model with an ``ImageField`` will also get this method. … … 2291 2318 according to your ``MEDIA_URL`` setting. If the value is blank, this method 2292 2319 returns an empty string. 2320 2321 .. note:: 2322 As with ``get_FOO_filename()``, it is only valid to call this method 2323 **after** saving the model, otherwise an incorrect result will be 2324 returned. 2293 2325 2294 2326 get_FOO_size() django/branches/gis/docs/django-admin.txt
r7918 r8215 396 396 Runs over the entire source tree of the current directory and pulls out all 397 397 strings marked for translation. It creates (or updates) a message file in the 398 conf/locale (in the django tree) or locale (for project and application)398 conf/locale (in the Django tree) or locale (for project and application) 399 399 directory. After making changes to the messages files you need to compile them 400 400 with ``compilemessages`` for use with the builtin gettext support. See the django/branches/gis/docs/email.txt
r7354 r8215 180 180 return HttpResponseRedirect('/contact/thanks/') 181 181 else: 182 # In reality we'd use a manipulator182 # In reality we'd use a form class 183 183 # to get proper validation errors. 184 184 return HttpResponse('Make sure all fields are entered and valid.') django/branches/gis/docs/faq.txt
r7642 r8215 225 225 --------------------------------- 226 226 227 Short answer: When we're comfortable with Django's APIs, have added all 228 features that we feel are necessary to earn a "1.0" status, and are ready to 229 begin maintaining backwards compatibility. 230 231 The merging of Django's `Queryset Refactor branch`_ went a long way toward Django 232 1.0. Merging the `Newforms Admin branch` will be another important step. 233 234 Of course, you should note that `quite a few production sites`_ use Django in 235 its current status. Don't let the lack of a 1.0 turn you off. 236 237 .. _Queryset Refactor branch: http://code.djangoproject.com/wiki/QuerysetRefactorBranch 238 .. _Newforms Admin branch: http://code.djangoproject.com/wiki/NewformsAdminBranch 239 .. _quite a few production sites: http://code.djangoproject.com/wiki/DjangoPoweredSites 227 See our `version one roadmap`_ for the detailed timeline. We're aiming for 228 September 2, 2008. 229 230 .. _version one roadmap: http://code.djangoproject.com/wiki/VersionOneRoadmap 240 231 241 232 How can I download the Django documentation to read it offline? … … 435 426 436 427 #. All that will be stored in your database is a path to the file 437 (relative to ``MEDIA_ROOT``). You'll m ust likely want to use the428 (relative to ``MEDIA_ROOT``). You'll most likely want to use the 438 429 convenience ``get_<fieldname>_url`` function provided by Django. For 439 430 example, if your ``ImageField`` is called ``mug_shot``, you can get the django/branches/gis/docs/fastcgi.txt
r7354 r8215 80 80 list of all the available options. 81 81 82 You'll need to specify either a ``socket``, ``protocol`` or both ``host`` and ``port``.83 Then, when you set up your Web server, you'll just need to point it at the host/port84 or socket you specified when starting the FastCGI server.82 You'll need to specify either a ``socket``, ``protocol`` or both ``host`` and 83 ``port``. Then, when you set up your Web server, you'll just need to point it 84 at the host/port or socket you specified when starting the FastCGI server. 85 85 86 86 Protocols … … 209 209 210 210 .. _mod_rewrite: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html 211 212 Django will automatically use the pre-rewrite version of the URL when 213 constructing URLs with the ``{% url %}`` template tag (and similar methods). 211 214 212 215 lighttpd setup … … 337 340 .. _modpython: ../modpython/#serving-the-admin-files 338 341 342 Forcing the URL prefix to a particular value 343 ============================================ 344 345 Because many of these fastcgi-based solutions require rewriting the URL at 346 some point inside th
