@@ -105,12 +105,12 @@ def __unicode__(self):
105
105
# If PIL is not available, ImageField tests are omitted.
106
106
from PIL import Image , _imaging
107
107
test_images = True
108
-
108
+
109
109
class ImageFile (models .Model ):
110
110
def custom_upload_path (self , filename ):
111
111
path = self .path or 'tests'
112
112
return '%s/%s' % (path , filename )
113
-
113
+
114
114
description = models .CharField (max_length = 20 )
115
115
image = models .ImageField (storage = temp_storage , upload_to = custom_upload_path ,
116
116
width_field = 'width' , height_field = 'height' )
@@ -120,15 +120,15 @@ def custom_upload_path(self, filename):
120
120
121
121
def __unicode__ (self ):
122
122
return self .description
123
-
123
+
124
124
class OptionalImageFile (models .Model ):
125
125
def custom_upload_path (self , filename ):
126
126
path = self .path or 'tests'
127
127
return '%s/%s' % (path , filename )
128
-
128
+
129
129
description = models .CharField (max_length = 20 )
130
130
image = models .ImageField (storage = temp_storage , upload_to = custom_upload_path ,
131
- width_field = 'width' , height_field = 'height' ,
131
+ width_field = 'width' , height_field = 'height' ,
132
132
blank = True , null = True )
133
133
width = models .IntegerField (editable = False , null = True )
134
134
height = models .IntegerField (editable = False , null = True )
@@ -138,7 +138,7 @@ def __unicode__(self):
138
138
return self .description
139
139
except ImportError :
140
140
test_images = False
141
-
141
+
142
142
class CommaSeparatedInteger (models .Model ):
143
143
field = models .CommaSeparatedIntegerField (max_length = 20 )
144
144
@@ -176,16 +176,16 @@ class Book(models.Model):
176
176
title = models .CharField (max_length = 40 )
177
177
author = models .ForeignKey (Writer , blank = True , null = True )
178
178
special_id = models .IntegerField (blank = True , null = True , unique = True )
179
-
179
+
180
180
class Meta :
181
181
unique_together = ('title' , 'author' )
182
-
182
+
183
183
class ExplicitPK (models .Model ):
184
184
key = models .CharField (max_length = 20 , primary_key = True )
185
185
desc = models .CharField (max_length = 20 , blank = True , unique = True )
186
186
class Meta :
187
187
unique_together = ('key' , 'desc' )
188
-
188
+
189
189
def __unicode__ (self ):
190
190
return self .key
191
191
@@ -331,6 +331,29 @@ def __unicode__(self):
331
331
<tr><th><label for="id_slug">Slug:</label></th><td><input id="id_slug" type="text" name="slug" maxlength="20" /></td></tr>
332
332
<tr><th><label for="id_checkbox">Checkbox:</label></th><td><input type="checkbox" name="checkbox" id="id_checkbox" /></td></tr>
333
333
334
+ # test using fields to provide ordering to the fields
335
+ >>> class CategoryForm(ModelForm):
336
+ ... class Meta:
337
+ ... model = Category
338
+ ... fields = ['url', 'name']
339
+
340
+ >>> CategoryForm.base_fields.keys()
341
+ ['url', 'name']
342
+
343
+
344
+ >>> print CategoryForm()
345
+ <tr><th><label for="id_url">The URL:</label></th><td><input id="id_url" type="text" name="url" maxlength="40" /></td></tr>
346
+ <tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="20" /></td></tr>
347
+
348
+ >>> class CategoryForm(ModelForm):
349
+ ... class Meta:
350
+ ... model = Category
351
+ ... fields = ['slug', 'url', 'name']
352
+ ... exclude = ['url']
353
+
354
+ >>> CategoryForm.base_fields.keys()
355
+ ['slug', 'name']
356
+
334
357
# Old form_for_x tests #######################################################
335
358
336
359
>>> from django.forms import ModelForm, CharField
@@ -1331,8 +1354,8 @@ def __unicode__(self):
1331
1354
True
1332
1355
1333
1356
# Unique & unique together with null values
1334
- >>> class BookForm(ModelForm):
1335
- ... class Meta:
1357
+ >>> class BookForm(ModelForm):
1358
+ ... class Meta:
1336
1359
... model = Book
1337
1360
>>> w = Writer.objects.get(name='Mike Royko')
1338
1361
>>> form = BookForm({'title': 'I May Be Wrong But I Doubt It', 'author' : w.pk})
0 commit comments