Changeset 5822 for django/branches/schema-evolution/docs
- Timestamp:
- 08/06/07 11:50:17 (1 year ago)
- Files:
-
- django/branches/schema-evolution/docs/add_ons.txt (modified) (1 diff)
- django/branches/schema-evolution/docs/api_stability.txt (modified) (2 diffs)
- django/branches/schema-evolution/docs/authentication.txt (modified) (1 diff)
- django/branches/schema-evolution/docs/contributing.txt (modified) (4 diffs)
- django/branches/schema-evolution/docs/databases.txt (modified) (1 diff)
- django/branches/schema-evolution/docs/db-api.txt (modified) (6 diffs)
- django/branches/schema-evolution/docs/email.txt (modified) (1 diff)
- django/branches/schema-evolution/docs/faq.txt (modified) (1 diff)
- django/branches/schema-evolution/docs/forms.txt (modified) (2 diffs)
- django/branches/schema-evolution/docs/model-api.txt (modified) (34 diffs)
- django/branches/schema-evolution/docs/newforms.txt (modified) (12 diffs)
- django/branches/schema-evolution/docs/overview.txt (modified) (4 diffs)
- django/branches/schema-evolution/docs/release_notes_0.95.txt (modified) (1 diff)
- django/branches/schema-evolution/docs/request_response.txt (modified) (1 diff)
- django/branches/schema-evolution/docs/sitemaps.txt (modified) (1 diff)
- django/branches/schema-evolution/docs/sites.txt (modified) (5 diffs)
- django/branches/schema-evolution/docs/testing.txt (modified) (1 diff)
- django/branches/schema-evolution/docs/tutorial01.txt (modified) (2 diffs)
- django/branches/schema-evolution/docs/tutorial02.txt (modified) (1 diff)
- django/branches/schema-evolution/docs/tutorial03.txt (modified) (1 diff)
- django/branches/schema-evolution/docs/tutorial04.txt (modified) (2 diffs)
- django/branches/schema-evolution/docs/url_dispatch.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/schema-evolution/docs/add_ons.txt
r5734 r5822 215 215 See the `syndication documentation`_. 216 216 217 .. _syndication documentation: ../syndication /217 .. _syndication documentation: ../syndication_feeds/ 218 218 219 219 Other add-ons django/branches/schema-evolution/docs/api_stability.txt
r5734 r5822 83 83 change: 84 84 85 - `Forms and validation`_ will most likely be completely rewritten to86 deemphasize Manipulators in favor of validation-aware models.87 88 85 - `Serialization`_ is under heavy development; changes are likely. 89 86 … … 115 112 .. _sessions: ../sessions/ 116 113 .. _settings: ../settings/ 117 .. _syndication: ../syndication /114 .. _syndication: ../syndication_feeds/ 118 115 .. _template language: ../templates/ 119 116 .. _transactions: ../transactions/ django/branches/schema-evolution/docs/authentication.txt
r5788 r5822 235 235 Previous Django versions, such as 0.90, used simple MD5 hashes without password 236 236 salts. For backwards compatibility, those are still supported; they'll be 237 converted automatically to the new style the first time `` check_password()``237 converted automatically to the new style the first time ``User.check_password()`` 238 238 works correctly for a given user. 239 239 django/branches/schema-evolution/docs/contributing.txt
r5788 r5822 341 341 342 342 class Person(models.Model): 343 first_name = models.CharField(max length=20)344 last_name = models.CharField(max length=40)343 first_name = models.CharField(max_length=20) 344 last_name = models.CharField(max_length=40) 345 345 346 346 Don't do this:: 347 347 348 348 class Person(models.Model): 349 FirstName = models.CharField(max length=20)350 Last_Name = models.CharField(max length=40)349 FirstName = models.CharField(max_length=20) 350 Last_Name = models.CharField(max_length=40) 351 351 352 352 * The ``class Meta`` should appear *after* the fields are defined, with … … 356 356 357 357 class Person(models.Model): 358 first_name = models.CharField(max length=20)359 last_name = models.CharField(max length=40)358 first_name = models.CharField(max_length=20) 359 last_name = models.CharField(max_length=40) 360 360 361 361 class Meta: … … 365 365 366 366 class Person(models.Model): 367 first_name = models.CharField(max length=20)368 last_name = models.CharField(max length=40)367 first_name = models.CharField(max_length=20) 368 last_name = models.CharField(max_length=40) 369 369 class Meta: 370 370 verbose_name_plural = 'people' … … 376 376 verbose_name_plural = 'people' 377 377 378 first_name = models.CharField(max length=20)379 last_name = models.CharField(max length=40)378 first_name = models.CharField(max_length=20) 379 last_name = models.CharField(max_length=40) 380 380 381 381 * The order of model inner classes and standard methods should be as django/branches/schema-evolution/docs/databases.txt
r5734 r5822 125 125 `MySQLdb documentation`_ for more details. 126 126 127 .. _settings documentation: http://www.djangoproject.com/documentation/settings/#database-engine127 .. _settings documentation: ../settings/#database-engine 128 128 .. _MySQL option file: http://dev.mysql.com/doc/refman/5.0/en/option-files.html 129 129 .. _MySQLdb documentation: http://mysql-python.sourceforge.net/ django/branches/schema-evolution/docs/db-api.txt
r5788 r5822 13 13 14 14 class Blog(models.Model): 15 name = models.CharField(max length=100)15 name = models.CharField(max_length=100) 16 16 tagline = models.TextField() 17 17 … … 20 20 21 21 class Author(models.Model): 22 name = models.CharField(max length=50)22 name = models.CharField(max_length=50) 23 23 email = models.EmailField() 24 24 … … 28 28 class Entry(models.Model): 29 29 blog = models.ForeignKey(Blog) 30 headline = models.CharField(max length=255)30 headline = models.CharField(max_length=255) 31 31 body_text = models.TextField() 32 32 pub_date = models.DateTimeField() … … 1504 1504 See the `OR lookups examples page`_ for more examples. 1505 1505 1506 .. _OR lookups examples page: http://www.djangoproject.com/documentation/models/or_lookups/1506 .. _OR lookups examples page: ../models/or_lookups/ 1507 1507 1508 1508 Related objects … … 1807 1807 ) 1808 1808 class Person(models.Model): 1809 name = models.CharField(max length=20)1810 gender = models.CharField(max length=1, choices=GENDER_CHOICES)1809 name = models.CharField(max_length=20) 1810 gender = models.CharField(max_length=1, choices=GENDER_CHOICES) 1811 1811 1812 1812 ...each ``Person`` instance will have a ``get_gender_display()`` method. Example:: … … 1835 1835 For a full example, see the `lookup API sample model`_. 1836 1836 1837 .. _lookup API sample model: http://www.djangoproject.com/documentation/models/lookup/1837 .. _lookup API sample model: ../models/lookup/ 1838 1838 1839 1839 get_FOO_filename() django/branches/schema-evolution/docs/email.txt
r5734 r5822 315 315 subject, from_email, to = 'hello', 'from@example.com', 'to@example.com' 316 316 text_content = 'This is an important message.' 317 html_content = '<p>This is an <strong>important</strong> message. '317 html_content = '<p>This is an <strong>important</strong> message.</p>' 318 318 msg = EmailMultiAlternatives(subject, text_content, from_email, to) 319 319 msg.attach_alternative(html_content, "text/html") django/branches/schema-evolution/docs/faq.txt
r5734 r5822 43 43 Django is pronounced **JANG**-oh. Rhymes with FANG-oh. The "D" is silent. 44 44 45 We've also recorded an `audio clip of the pronunciation`_. 46 45 47 .. _Django Reinhardt: http://en.wikipedia.org/wiki/Django_Reinhardt 48 .. _audio clip of the pronunciation: http://red-bean.com/~adrian/django_pronunciation.mp3 46 49 47 50 Is Django stable? django/branches/schema-evolution/docs/forms.txt
r5734 r5822 38 38 39 39 class Place(models.Model): 40 name = models.CharField(max length=100)41 address = models.CharField(max length=100, blank=True)42 city = models.CharField(max length=50, blank=True)40 name = models.CharField(max_length=100) 41 address = models.CharField(max_length=100, blank=True) 42 city = models.CharField(max_length=50, blank=True) 43 43 state = models.USStateField() 44 zip_code = models.CharField(max length=5, blank=True)44 zip_code = models.CharField(max_length=5, blank=True) 45 45 place_type = models.IntegerField(choices=PLACE_TYPES) 46 46 … … 389 389 self.fields = ( 390 390 forms.EmailField(field_name="from", is_required=True), 391 forms.TextField(field_name="subject", length=30, max length=200, is_required=True),391 forms.TextField(field_name="subject", length=30, max_length=200, is_required=True), 392 392 forms.SelectField(field_name="urgency", choices=urgency_choices), 393 393 forms.LargeTextField(field_name="contents", is_required=True), django/branches/schema-evolution/docs/model-api.txt
r5788 r5822 23 23 24 24 .. _Database API reference: ../db-api/ 25 .. _official repository of model examples: http://www.djangoproject.com/documentation/models/25 .. _official repository of model examples: ../models/ 26 26 27 27 Quick example … … 34 34 35 35 class Person(models.Model): 36 first_name = models.CharField(max length=30)37 last_name = models.CharField(max length=30)36 first_name = models.CharField(max_length=30) 37 last_name = models.CharField(max_length=30) 38 38 39 39 ``first_name`` and ``last_name`` are *fields* of the model. Each field is … … 70 70 71 71 class Musician(models.Model): 72 first_name = models.CharField(max length=50)73 last_name = models.CharField(max length=50)74 instrument = models.CharField(max length=100)72 first_name = models.CharField(max_length=50) 73 last_name = models.CharField(max_length=50) 74 instrument = models.CharField(max_length=100) 75 75 76 76 class Album(models.Model): 77 77 artist = models.ForeignKey(Musician) 78 name = models.CharField(max length=100)78 name = models.CharField(max_length=100) 79 79 release_date = models.DateField() 80 80 num_stars = models.IntegerField() … … 143 143 The admin represents this as an ``<input type="text">`` (a single-line input). 144 144 145 ``CharField`` has an extra required argument, ``max length``, the maximum length146 (in characters) of the field. The max length is enforced at the database level145 ``CharField`` has an extra required argument, ``max_length``, the maximum length 146 (in characters) of the field. The max_length is enforced at the database level 147 147 and in Django's validation. 148 148 149 ``CommaSeparatedIntegerField`` 149 Django veterans: Note that the argument is now called ``max_length`` to 150 provide consistency throughout Django. There is full legacy support for 151 the old ``maxlength`` argument, but ``max_length`` is prefered. 152 153 ``CommaSeparatedIntegerField`` 150 154 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 151 155 152 A field of integers separated by commas. As in ``CharField``, the ``max length``156 A field of integers separated by commas. As in ``CharField``, the ``max_length`` 153 157 argument is required. 154 158 … … 218 222 219 223 A ``CharField`` that checks that the value is a valid e-mail address. 220 This doesn't accept ``max length``; its ``maxlength`` is automatically set to224 This doesn't accept ``max_length``; its ``max_length`` is automatically set to 221 225 75. 222 226 … … 401 405 used in URLs. 402 406 403 Like a CharField, you can specify ``max length``. If ``maxlength`` is407 Like a CharField, you can specify ``max_length``. If ``max_length`` is 404 408 not specified, Django will use a default length of 50. 405 409 … … 448 452 The admin represents this as an ``<input type="text">`` (a single-line input). 449 453 450 ``URLField`` takes an optional argument, ``max length``, the maximum length (in451 characters) of the field. The max length is enforced at the database level and452 in Django's validation. If you don't specify ``max length``, a default of 200454 ``URLField`` takes an optional argument, ``max_length``, the maximum length (in 455 characters) of the field. The maximum length is enforced at the database level and 456 in Django's validation. If you don't specify ``max_length``, a default of 200 453 457 is used. 454 458 … … 537 541 ('F', 'Female'), 538 542 ) 539 gender = models.CharField(max length=1, choices=GENDER_CHOICES)543 gender = models.CharField(max_length=1, choices=GENDER_CHOICES) 540 544 541 545 or outside your model class altogether:: … … 546 550 ) 547 551 class Foo(models.Model): 548 gender = models.CharField(max length=1, choices=GENDER_CHOICES)552 gender = models.CharField(max_length=1, choices=GENDER_CHOICES) 549 553 550 554 For each model field that has ``choices`` set, Django will add a method to … … 621 625 admin form. 622 626 627 Note that this value is *not* HTML-escaped when it's displayed in the admin 628 interface. This lets you include HTML in ``help_text`` if you so desire. For 629 example:: 630 631 help_text="Please use the following format: <em>YYYY-MM-DD</em>." 632 623 633 ``primary_key`` 624 634 ~~~~~~~~~~~~~~~ … … 699 709 In this example, the verbose name is ``"Person's first name"``:: 700 710 701 first_name = models.CharField("Person's first name", max length=30)711 first_name = models.CharField("Person's first name", max_length=30) 702 712 703 713 In this example, the verbose name is ``"first name"``:: 704 714 705 first_name = models.CharField(max length=30)715 first_name = models.CharField(max_length=30) 706 716 707 717 ``ForeignKey``, ``ManyToManyField`` and ``OneToOneField`` require the first … … 776 786 See the `Many-to-one relationship model example`_ for a full example. 777 787 778 .. _Many-to-one relationship model example: http://www.djangoproject.com/documentation/models/many_to_one/788 .. _Many-to-one relationship model example: ../models/many_to_one/ 779 789 780 790 ``ForeignKey`` fields take a number of extra arguments for defining how the … … 903 913 See the `Many-to-many relationship model example`_ for a full example. 904 914 905 .. _Many-to-many relationship model example: http://www.djangoproject.com/documentation/models/many_to_many/915 .. _Many-to-many relationship model example: ../models/many_to_many/ 906 916 907 917 ``ManyToManyField`` objects take a number of extra arguments for defining how … … 980 990 See the `One-to-one relationship model example`_ for a full example. 981 991 982 .. _One-to-one relationship model example: http://www.djangoproject.com/documentation/models/one_to_one/992 .. _One-to-one relationship model example: ../models/one_to_one/ 983 993 984 994 Custom field types … … 1028 1038 1029 1039 class Person(models.Model): 1030 name = models.CharField(max length=80)1031 gender = models.CharField(max length=1)1040 name = models.CharField(max_length=80) 1041 gender = models.CharField(max_length=1) 1032 1042 something_else = MytypeField() 1033 1043 … … 1075 1085 # This is a much more flexible example. 1076 1086 class BetterCharField(models.Field): 1077 def __init__(self, max length, *args, **kwargs):1078 self.max length = maxlength1087 def __init__(self, max_length, *args, **kwargs): 1088 self.max_length = max_length 1079 1089 super(BetterCharField, self).__init__(*args, **kwargs) 1080 1090 1081 1091 def db_type(self): 1082 return 'char(%s)' % self.max length1092 return 'char(%s)' % self.max_length 1083 1093 1084 1094 # In the model: … … 1097 1107 1098 1108 class Foo(models.Model): 1099 bar = models.CharField(max length=30)1109 bar = models.CharField(max_length=30) 1100 1110 1101 1111 class Meta: … … 1187 1197 site uses only the first field. 1188 1198 1189 .. _Specifying ordering: http://www.djangoproject.com/documentation/models/ordering/1199 .. _Specifying ordering: ../models/ordering/ 1190 1200 1191 1201 ``permissions`` … … 1271 1281 1272 1282 class Person(models.Model): 1273 first_name = models.CharField(max length=30)1274 last_name = models.CharField(max length=30)1283 first_name = models.CharField(max_length=30) 1284 last_name = models.CharField(max_length=30) 1275 1285 1276 1286 class Admin: … … 1431 1441 1432 1442 class Person(models.Model): 1433 name = models.CharField(max length=50)1443 name = models.CharField(max_length=50) 1434 1444 birthday = models.DateField() 1435 1445 … … 1448 1458 1449 1459 class Person(models.Model): 1450 first_name = models.CharField(max length=50)1451 last_name = models.CharField(max length=50)1452 color_code = models.CharField(max length=6)1460 first_name = models.CharField(max_length=50) 1461 last_name = models.CharField(max_length=50) 1462 color_code = models.CharField(max_length=6) 1453 1463 1454 1464 class Admin: … … 1466 1476 1467 1477 class Person(models.Model): 1468 first_name = models.CharField(max length=50)1478 first_name = models.CharField(max_length=50) 1469 1479 birthday = models.DateField() 1470 1480 … … 1494 1504 1495 1505 class Person(models.Model): 1496 first_name = models.CharField(max length=50)1497 color_code = models.CharField(max length=6)1506 first_name = models.CharField(max_length=50) 1507 color_code = models.CharField(max_length=6) 1498 1508 1499 1509 class Admin: … … 1745 1755 1746 1756 class OpinionPoll(models.Model): 1747 question = models.CharField(max length=200)1757 question = models.CharField(max_length=200) 1748 1758 poll_date = models.DateField() 1749 1759 objects = PollManager() … … 1751 1761 class Response(models.Model): 1752 1762 poll = models.ForeignKey(Poll) 1753 person_name = models.CharField(max length=50)1763 person_name = models.CharField(max_length=50) 1754 1764 response = models.TextField() 1755 1765 … … 1767 1777 1768 1778 class Book(models.Model): 1769 title = models.CharField(max length=100)1770 author = models.CharField(max length=50)1779 title = models.CharField(max_length=100) 1780 author = models.CharField(max_length=50) 1771 1781 1772 1782 ...the statement ``Book.objects.all()`` will return all books in the database. … … 1786 1796 # Then hook it into the Book model explicitly. 1787 1797 class Book(models.Model): 1788 title = models.CharField(max length=100)1789 author = models.CharField(max length=50)1798 title = models.CharField(max_length=100) 1799 author = models.CharField(max_length=50) 1790 1800 1791 1801 objects = models.Manager() # The default manager. … … 1820 1830 1821 1831 class Person(models.Model): 1822 first_name = models.CharField(max length=50)1823 last_name = models.CharField(max length=50)1824 sex = models.CharField(max length=1, choices=(('M', 'Male'), ('F', 'Female')))1832 first_name = models.CharField(max_length=50) 1833 last_name = models.CharField(max_length=50) 1834 sex = models.CharField(max_length=1, choices=(('M', 'Male'), ('F', 'Female'))) 1825 1835 people = models.Manager() 1826 1836 men = MaleManager() … … 1852 1862 1853 1863 class Person(models.Model): 1854 first_name = models.CharField(max length=50)1855 last_name = models.CharField(max length=50)1864 first_name = models.CharField(max_length=50) 1865 last_name = models.CharField(max_length=50) 1856 1866 birth_date = models.DateField() 1857 address = models.CharField(max length=100)1858 city = models.CharField(max length=50)1867 address = models.CharField(max_length=100) 1868 city = models.CharField(max_length=50) 1859 1869 state = models.USStateField() # Yes, this is America-centric... 1860 1870 … … 1898 1908 1899 1909 class Person(models.Model): 1900 first_name = models.CharField(max length=50)1901 last_name = models.CharField(max length=50)1910 first_name = models.CharField(max_length=50) 1911 last_name = models.CharField(max_length=50) 1902 1912 1903 1913 def __str__(self): … … 1916 1926 1917 1927 class Person(models.Model): 1918 first_name = models.CharField(max length=50)1919 last_name = models.CharField(max length=50)1928 first_name = models.CharField(max_length=50) 1929 last_name = models.CharField(max_length=50) 1920 1930 1921 1931 def __unicode__(self): … … 1943 1953 ``get_absolute_url()``. 1944 1954 1945 Also, a couple of other bits of Django, such as the syndication-feed framework,1955 Also, a couple of other bits of Django, such as the `syndication feed framework`_, 1946 1956 use ``get_absolute_url()`` as a convenience to reward people who've defined the 1947 1957 method. 1958 1959 .. syndication feed framework: ../syndication_feeds/ 1948 1960 1949 1961 It's good practice to use ``get_absolute_url()`` in templates, instead of … … 2057 2069 2058 2070 class Blog(models.Model): 2059 name = models.CharField(max length=100)2071 name = models.CharField(max_length=100) 2060 2072 tagline = models.TextField() 2061 2073 … … 2068 2080 2069 2081 class Blog(models.Model): 2070 name = models.CharField(max length=100)2082 name = models.CharField(max_length=100) 2071 2083 tagline = models.TextField() 2072 2084 django/branches/schema-evolution/docs/newforms.txt
r5734 r5822 642 642 like this:: 643 643 644 <form method="post" >644 <form method="post" action=""> 645 645 <table>{{ form }}</table> 646 646 <input type="submit" /> … … 654 654 The following is equivalent but a bit more explicit:: 655 655 656 <form method="post" >656 <form method="post" action=""> 657 657 <table>{{ form.as_table }}</table> 658 658 <input type="submit" /> … … 676 676 ``{% for field in form %}``. For example:: 677 677 678 <form method="post" >678 <form method="post" action=""> 679 679 <dl> 680 680 {% for field in form %} … … 697 697 For example:: 698 698 699 <form method="post" >699 <form method="post" action=""> 700 700 <ul class="myformclass"> 701 701 <li>{{ form.sender.label }} {{ form.sender }}</li> … … 710 710 </ul> 711 711 </form> 712 713 Binding uploaded files to a form 714 -------------------------------- 715 716 **New in Django development version** 717 718 Dealing with forms that have ``FileField`` and ``ImageField`` fields 719 is a little more complicated than a normal form. 720 721 Firstly, in order to upload files, you'll need to make sure that your 722 ``<form>`` element correctly defines the ``enctype`` as 723 ``"multipart/form-data"``:: 724 725 <form enctype="multipart/form-data" method="post" action="/foo/"> 726 727 Secondly, when you use the form, you need to bind the file data. File 728 data is handled separately to normal form data, so when your form 729 contains a ``FileField`` and ``ImageField``, you will need to specify 730 a second argument when you bind your form. So if we extend our 731 ContactForm to include an ``ImageField`` called ``mugshot``, we 732 need to bind the file data containing the mugshot image:: 733 734 # Bound form with an image field 735 >>> data = {'subject': 'hello', 736 ... 'message': 'Hi there', 737 ... 'sender': 'foo@example.com', 738 ... 'cc_myself': True} 739 >>> file_data = {'mugshot': {'filename':'face.jpg' 740 ... 'content': <file data>}} 741 >>> f = ContactFormWithMugshot(data, file_data) 742 743 In practice, you will usually specify ``request.FILES`` as the source 744 of file data (just like you use ``request.POST`` as the source of 745 form data):: 746 747 # Bound form with an image field, data from the request 748 >>> f = ContactFormWithMugshot(request.POST, request.FILES) 749 750 Constructing an unbound form is the same as always -- just omit both 751 form data *and* file data: 752 753 # Unbound form with a image field 754 >>> f = ContactFormWithMugshot() 712 755 713 756 Subclassing forms … … 1100 1143 given length. 1101 1144 1145 ``FileField`` 1146 ~~~~~~~~~~~~~ 1147 1148 **New in Django development version** 1149 1150 * Default widget: ``FileInput`` 1151 * Empty value: ``None`` 1152 * Normalizes to: An ``UploadedFile`` object that wraps the file content 1153 and file name into a single object. 1154 * Validates that non-empty file data has been bound to the form. 1155 1156 An ``UploadedFile`` object has two attributes: 1157 1158 ====================== ===================================================== 1159 Argument Description 1160 ====================== ===================================================== 1161 ``filename`` The name of the file, provided by the uploading 1162 client. 1163 ``content`` The array of bytes comprising the file content. 1164 ====================== ===================================================== 1165 1166 The string representation of an ``UploadedFile`` is the same as the filename 1167 attribute. 1168 1169 When you use a ``FileField`` on a form, you must also remember to 1170 `bind the file data to the form`_. 1171 1172 .. _`bind the file data to the form`: `Binding uploaded files to a form`_ 1173 1174 ``ImageField`` 1175 ~~~~~~~~~~~~~~ 1176 1177 **New in Django development version** 1178 1179 * Default widget: ``FileInput`` 1180 * Empty value: ``None`` 1181 * Normalizes to: An ``UploadedFile`` object that wraps the file content 1182 and file name into a single object. 1183 * Validates that file data has been bound to the form, and that the 1184 file is of an image format understood by PIL. 1185 1186 Using an ImageField requires that the `Python Imaging Library`_ is installed. 1187 1188 When you use a ``FileField`` on a form, you must also remember to 1189 `bind the file data to the form`_. 1190 1191 .. _Python Imaging Library: http://www.pythonware.com/products/pil/ 1192 1102 1193 ``IntegerField`` 1103 1194 ~~~~~~~~~~~~~~~~ … … 1223 1314 Form validation happens when the data is cleaned. If you want to customise 1224 1315 this process, there are various places you can change, each one serving a 1225 different purpose. Th ee types of cleaning methods are run during form1316 different purpose. Three types of cleaning methods are run during form 1226 1317 processing. These are normally executed when you call the ``is_valid()`` 1227 1318 method on a form. There are other things that can trigger cleaning and … … 1373 1464 ``BooleanField`` ``BooleanField`` 1374 1465 ``CharField`` ``CharField`` with ``max_length`` set to 1375 the model field's ``max length``1466 the model field's ``max_length`` 1376 1467 ``CommaSeparatedIntegerField`` ``CharField`` 1377 1468 ``DateField`` ``DateField`` … … 1379 1470 ``DecimalField`` ``DecimalField`` 1380 1471 ``EmailField`` ``EmailField`` 1381 ``FileField`` `` CharField``1472 ``FileField`` ``FileField`` 1382 1473 ``FilePathField`` ``CharField`` 1383 1474 ``FloatField`` ``FloatField`` 1384 1475 ``ForeignKey`` ``ModelChoiceField`` (see below) 1385 ``ImageField`` `` CharField``1476 ``ImageField`` ``ImageField`` 1386 1477 ``IntegerField`` ``IntegerField`` 1387 1478 ``IPAddressField`` ``CharField`` … … 1453 1544 1454 1545 class Author(models.Model): 1455 name = models.CharField(max length=100)1456 title = models.CharField(max length=3, choices=TITLE_CHOICES)1546 name = models.CharField(max_length=100) 1547 title = models.CharField(max_length=3, choices=TITLE_CHOICES) 1457 1548 birth_date = models.DateField(blank=True, null=True) 1458 1549 … … 1461 1552 1462 1553 class Book(models.Model): 1463 name = models.CharField(max length=100)1554 name = models.CharField(max_length=100) 1464 1555 authors = models.ManyToManyField(Author) 1465 1556 … … 1503 1594 object before saving it. ``commit`` is ``True`` by default. 1504 1595 1596 Another side effect of using ``commit=False`` is seen when your model has 1597 a many-to-many relation with another model. If your model has a many-to-many 1598 relation and you specify ``commit=False`` when you save a form, Django cannot 1599 immediately save the form data for the many-to-many relation. This is because 1600 it isn't possible to save many-to-many data for an instance until the instance 1601 exists in the database. 1602 1603 To work around this problem, every time you save a form using ``commit=False``, 1604 Django adds a ``save_m2m()`` method to the form created by ``form_for_model``. 1605 After you've manually saved the instance produced by the form, you can invoke 1606 ``save_m2m()`` to save the many-to-many form data. For example:: 1607 1608 # Create a form instance with POST data. 1609 >>> f = AuthorForm(request.POST) 1610 1611 # Create, but don't save the new author instance. 1612 >>> new_author = f.save(commit=False) 1613 1614 # Modify the author in some way. 1615 >>> new_author.some_field = 'some_value' 1616 1617 # Save the new instance. 1618 >>> new_author.save() 1619 1620 # Now, save the many-to-many data for the form. 1621 >>> f.save_m2m() 1622 1623 Calling ``save_m2m()`` is only required if you use ``save(commit=False)``. 1624 When you use a simple ``save()`` on a form, all data -- including 1625 many-to-many data -- is saved without the need for any additional method calls. 1626 For example:: 1627 1628 # Create a form instance with POST data. 1629 >>> f = AuthorForm(request.POST) 1630 1631 # Create and save the new author instance. There's no need to do anything else. 1632 >>> new_author = f.save() 1633 1505 1634 Using an alternate base class 1506 1635 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ django/branches/schema-evolution/docs/overview.txt
r5734 r5822 26 26 27 27 class Reporter(models.Model): 28 full_name = models.CharField(max length=70)28 full_name = models.CharField(max_length=70) 29 29 30 30 def __unicode__(self): … … 33 33 class Article(models.Model): 34 34 pub_date = models.DateTimeField() 35 headline = models.CharField(max length=200)35 headline = models.CharField(max_length=200) 36 36 article = models.TextField() 37 37 reporter = models.ForeignKey(Reporter) … … 135 135 class Article(models.Model): 136 136 pub_date = models.DateTimeField() 137 headline = models.CharField(max length=200)137 headline = models.CharField(max_length=200) 138 138 article = models.TextField() 139 139 reporter = models.ForeignKey(Reporter) … … 289 289 290 290 * A caching framework that integrates with memcached or other backends. 291 * A syndication frameworkthat makes creating RSS and Atom feeds as easy as291 * A `syndication framework`_ that makes creating RSS and Atom feeds as easy as 292 292 writing a small Python class. 293 293 * More sexy automatically-generated admin features -- this overview barely 294 294 scratched the surface. 295 295 296 .. _syndication framework: ../syndication_feeds/ 297 296 298 The next obvious steps are for you to `download Django`_, read `the tutorial`_ 297 299 and join `the community`_. Thanks for your interest! 298 300 299 301 .. _download Django: http://www.djangoproject.com/download/ 300 .. _the tutorial: http://www.djangoproject.com/documentation/tutorial01/302 .. _the tutorial: ../tutorial01/ 301 303 .. _the community: http://www.djangoproject.com/community/ django/branches/schema-evolution/docs/release_notes_0.95.txt
r3937 r5822 115 115 available at any hour of the day -- to help, or just to chat. 116 116 117 .. _online: http://www.djangoproject.com/documentation/ 117 .. _online: http://www.djangoproject.com/documentation/0.95/ 118 118 .. _Django website: http://www.djangoproject.com/ 119 119 .. _FAQ: http://www.djangoproject.com/documentation/faq/ django/branches/schema-evolution/docs/request_response.txt
r5734 r5822 298 298 is responsible for instantiating, populating and returning an ``HttpResponse``. 299 299 300 The ``HttpResponse`` class lives at ``django.http.HttpResponse``.300 The ``HttpResponse`` class lives in the ``django.http`` module. 301 301 302 302 Usage django/branches/schema-evolution/docs/sitemaps.txt
r5734 r5822 22 22 write a ``Sitemap`` class and point to it in your URLconf_. 23 23 24 .. _syndication framework: ../syndication /24 .. _syndication framework: ../syndication_feeds/ 25 25 .. _URLconf: ../url_dispatch/ 26 26 django/branches/schema-evolution/docs/sites.txt
r5734 r5822 47 47 48 48 class Article(models.Model): 49 headline = models.CharField(max length=200)49 headline = models.CharField(max_length=200) 50 50 # ... 51 51 sites = models.ManyToManyField(Site) … … 88 88 89 89 class Article(models.Model): 90 headline = models.CharField(max length=200)90 headline = models.CharField(max_length=200) 91 91 # ... 92 92 site = models.ForeignKey(Site) … … 230 230 class Photo(models.Model): 231 231 photo = models.FileField(upload_to='/home/photos') 232 photographer_name = models.CharField(max length=100)232 photographer_name = models.CharField(max_length=100) 233 233 pub_date = models.DateField() 234 234 site = models.ForeignKey(Site) … … 258 258 class Photo(models.Model): 259 259 photo = models.FileField(upload_to='/home/photos') 260 photographer_name = models.CharField(max length=100)260 photographer_name = models.CharField(max_length=100) 261 261
