Ticket #6953: 6953.diff

File 6953.diff, 7.0 KB (added by David Gouldin, 16 years ago)
  • django/forms/models.py

     
    134134    fields will be excluded from the returned fields, even if they are listed
    135135    in the ``fields`` argument.
    136136    """
    137     # TODO: if fields is provided, it would be nice to return fields in that order
     137
    138138    field_list = []
    139139    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:
    141143        if not f.editable:
    142144            continue
    143145        if fields and not f.name in fields:
  • tests/modeltests/model_forms/models.py

     
    236236OddForm is now an Article-related thing, because BadForm.Meta overrides
    237237CategoryForm.Meta.
    238238>>> OddForm.base_fields.keys()
    239 ['headline', 'slug', 'pub_date', 'writer', 'article', 'status', 'categories']
     239['headline', 'slug', 'pub_date', 'writer', 'article', 'categories', 'status']
    240240
    241241>>> class ArticleForm(ModelForm):
    242242...     class Meta:
     
    247247>>> class BadForm(ArticleForm, CategoryForm):
    248248...     pass
    249249>>> OddForm.base_fields.keys()
    250 ['headline', 'slug', 'pub_date', 'writer', 'article', 'status', 'categories']
     250['headline', 'slug', 'pub_date', 'writer', 'article', 'categories', 'status']
    251251
    252252Subclassing without specifying a Meta on the class will use the parent's Meta
    253253(or the first parent in the MRO if there are multiple parent classes).
     
    398398<option value="2">Bob Woodward</option>
    399399</select></td></tr>
    400400<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&#39;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>
    401406<tr><th>Status:</th><td><select name="status">
    402407<option value="" selected="selected">---------</option>
    403408<option value="1">Draft</option>
    404409<option value="2">Pending</option>
    405410<option value="3">Live</option>
    406411</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&#39;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>
    412412
    413413You can restrict a form to a subset of the complete list of fields
    414414by providing a 'fields' argument. If you try to save a
     
    453453<option value="2">Bob Woodward</option>
    454454</select></li>
    455455<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&#39;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>
    456461<li>Status: <select name="status">
    457462<option value="" selected="selected">---------</option>
    458463<option value="1">Draft</option>
    459464<option value="2">Pending</option>
    460465<option value="3">Live</option>
    461466</select></li>
    462 <li>Categories: <select multiple="multiple" name="categories">
    463 <option value="1">Entertainment</option>
    464 <option value="2">It&#39;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>
    467467>>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': u'1', 'article': 'Hello.'}, instance=art)
    468468>>> f.is_valid()
    469469True
     
    514514<option value="2">Bob Woodward</option>
    515515</select></li>
    516516<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&#39;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>
    517522<li>Status: <select name="status">
    518523<option value="" selected="selected">---------</option>
    519524<option value="1">Draft</option>
    520525<option value="2">Pending</option>
    521526<option value="3">Live</option>
    522527</select></li>
    523 <li>Categories: <select multiple="multiple" name="categories">
    524 <option value="1" selected="selected">Entertainment</option>
    525 <option value="2">It&#39;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>
    528528
    529529>>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04',
    530530...     'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art)
     
    630630<option value="2">Bob Woodward</option>
    631631</select></li>
    632632<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&#39;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>
    633638<li>Status: <select name="status">
    634639<option value="" selected="selected">---------</option>
    635640<option value="1">Draft</option>
    636641<option value="2">Pending</option>
    637642<option value="3">Live</option>
    638643</select></li>
    639 <li>Categories: <select multiple="multiple" name="categories">
    640 <option value="1">Entertainment</option>
    641 <option value="2">It&#39;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>
    644644>>> Category.objects.create(name='Fourth', url='4th')
    645645<Category: Fourth>
    646646>>> Writer.objects.create(name='Carl Bernstein')
     
    656656<option value="3">Carl Bernstein</option>
    657657</select></li>
    658658<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&#39;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>
    659665<li>Status: <select name="status">
    660666<option value="" selected="selected">---------</option>
    661667<option value="1">Draft</option>
    662668<option value="2">Pending</option>
    663669<option value="3">Live</option>
    664670</select></li>
    665 <li>Categories: <select multiple="multiple" name="categories">
    666 <option value="1">Entertainment</option>
    667 <option value="2">It&#39;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>
    671671
    672672# ModelChoiceField ############################################################
    673673
Back to Top