Ticket #6953: 6953.diff
File 6953.diff, 7.0 KB (added by , 16 years ago) |
---|
-
django/forms/models.py
134 134 fields will be excluded from the returned fields, even if they are listed 135 135 in the ``fields`` argument. 136 136 """ 137 # TODO: if fields is provided, it would be nice to return fields in that order 137 138 138 field_list = [] 139 139 opts = model._meta 140 for f in opts.fields + opts.many_to_many: 140 model_fields = opts.fields + opts.many_to_many 141 model_fields.sort() 142 for f in model_fields: 141 143 if not f.editable: 142 144 continue 143 145 if fields and not f.name in fields: -
tests/modeltests/model_forms/models.py
236 236 OddForm is now an Article-related thing, because BadForm.Meta overrides 237 237 CategoryForm.Meta. 238 238 >>> OddForm.base_fields.keys() 239 ['headline', 'slug', 'pub_date', 'writer', 'article', ' status', 'categories']239 ['headline', 'slug', 'pub_date', 'writer', 'article', 'categories', 'status'] 240 240 241 241 >>> class ArticleForm(ModelForm): 242 242 ... class Meta: … … 247 247 >>> class BadForm(ArticleForm, CategoryForm): 248 248 ... pass 249 249 >>> OddForm.base_fields.keys() 250 ['headline', 'slug', 'pub_date', 'writer', 'article', ' status', 'categories']250 ['headline', 'slug', 'pub_date', 'writer', 'article', 'categories', 'status'] 251 251 252 252 Subclassing without specifying a Meta on the class will use the parent's Meta 253 253 (or the first parent in the MRO if there are multiple parent classes). … … 398 398 <option value="2">Bob Woodward</option> 399 399 </select></td></tr> 400 400 <tr><th>Article:</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr> 401 <tr><th>Categories:</th><td><select multiple="multiple" name="categories"> 402 <option value="1">Entertainment</option> 403 <option value="2">It's a test</option> 404 <option value="3">Third test</option> 405 </select><br /> Hold down "Control", or "Command" on a Mac, to select more than one.</td></tr> 401 406 <tr><th>Status:</th><td><select name="status"> 402 407 <option value="" selected="selected">---------</option> 403 408 <option value="1">Draft</option> 404 409 <option value="2">Pending</option> 405 410 <option value="3">Live</option> 406 411 </select></td></tr> 407 <tr><th>Categories:</th><td><select multiple="multiple" name="categories">408 <option value="1">Entertainment</option>409 <option value="2">It's a test</option>410 <option value="3">Third test</option>411 </select><br /> Hold down "Control", or "Command" on a Mac, to select more than one.</td></tr>412 412 413 413 You can restrict a form to a subset of the complete list of fields 414 414 by providing a 'fields' argument. If you try to save a … … 453 453 <option value="2">Bob Woodward</option> 454 454 </select></li> 455 455 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li> 456 <li>Categories: <select multiple="multiple" name="categories"> 457 <option value="1">Entertainment</option> 458 <option value="2">It's a test</option> 459 <option value="3">Third test</option> 460 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> 456 461 <li>Status: <select name="status"> 457 462 <option value="" selected="selected">---------</option> 458 463 <option value="1">Draft</option> 459 464 <option value="2">Pending</option> 460 465 <option value="3">Live</option> 461 466 </select></li> 462 <li>Categories: <select multiple="multiple" name="categories">463 <option value="1">Entertainment</option>464 <option value="2">It's a test</option>465 <option value="3">Third test</option>466 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>467 467 >>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': u'1', 'article': 'Hello.'}, instance=art) 468 468 >>> f.is_valid() 469 469 True … … 514 514 <option value="2">Bob Woodward</option> 515 515 </select></li> 516 516 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li> 517 <li>Categories: <select multiple="multiple" name="categories"> 518 <option value="1" selected="selected">Entertainment</option> 519 <option value="2">It's a test</option> 520 <option value="3">Third test</option> 521 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> 517 522 <li>Status: <select name="status"> 518 523 <option value="" selected="selected">---------</option> 519 524 <option value="1">Draft</option> 520 525 <option value="2">Pending</option> 521 526 <option value="3">Live</option> 522 527 </select></li> 523 <li>Categories: <select multiple="multiple" name="categories">524 <option value="1" selected="selected">Entertainment</option>525 <option value="2">It's a test</option>526 <option value="3">Third test</option>527 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>528 528 529 529 >>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04', 530 530 ... 'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art) … … 630 630 <option value="2">Bob Woodward</option> 631 631 </select></li> 632 632 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li> 633 <li>Categories: <select multiple="multiple" name="categories"> 634 <option value="1">Entertainment</option> 635 <option value="2">It's a test</option> 636 <option value="3">Third</option> 637 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> 633 638 <li>Status: <select name="status"> 634 639 <option value="" selected="selected">---------</option> 635 640 <option value="1">Draft</option> 636 641 <option value="2">Pending</option> 637 642 <option value="3">Live</option> 638 643 </select></li> 639 <li>Categories: <select multiple="multiple" name="categories">640 <option value="1">Entertainment</option>641 <option value="2">It's a test</option>642 <option value="3">Third</option>643 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>644 644 >>> Category.objects.create(name='Fourth', url='4th') 645 645 <Category: Fourth> 646 646 >>> Writer.objects.create(name='Carl Bernstein') … … 656 656 <option value="3">Carl Bernstein</option> 657 657 </select></li> 658 658 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li> 659 <li>Categories: <select multiple="multiple" name="categories"> 660 <option value="1">Entertainment</option> 661 <option value="2">It's a test</option> 662 <option value="3">Third</option> 663 <option value="4">Fourth</option> 664 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> 659 665 <li>Status: <select name="status"> 660 666 <option value="" selected="selected">---------</option> 661 667 <option value="1">Draft</option> 662 668 <option value="2">Pending</option> 663 669 <option value="3">Live</option> 664 670 </select></li> 665 <li>Categories: <select multiple="multiple" name="categories">666 <option value="1">Entertainment</option>667 <option value="2">It's a test</option>668 <option value="3">Third</option>669 <option value="4">Fourth</option>670 </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li>671 671 672 672 # ModelChoiceField ############################################################ 673 673