Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Revert "Began implementing a shared set of test models to speed up te…

…sts."

This reverts commit 22b7870.
  • Loading branch information...
commit f5d4849cbeda994e7d2e43c4aaf2aac69d5c95bb 1 parent dfcce42
Florian Apolloner authored June 10, 2013
284  tests/lookup/tests.py
@@ -5,7 +5,6 @@
5 5
 
6 6
 from django.core.exceptions import FieldError
7 7
 from django.test import TestCase, skipUnlessDBFeature
8  
-from django.utils import six
9 8
 
10 9
 from shared_models.models import Author, Book
11 10
 
@@ -21,19 +20,19 @@ def setUp(self):
21 20
         self.au2 = Author(name='Author 2')
22 21
         self.au2.save()
23 22
         # Create a couple of Books.
24  
-        self.b1 = Book(title='Book 1', pubdate=datetime(2005, 7, 26), author=self.au1)
  23
+        self.b1 = Book(name='Book 1', pubdate=datetime(2005, 7, 26), author=self.au1)
25 24
         self.b1.save()
26  
-        self.b2 = Book(title='Book 2', pubdate=datetime(2005, 7, 27), author=self.au1)
  25
+        self.b2 = Book(name='Book 2', pubdate=datetime(2005, 7, 27), author=self.au1)
27 26
         self.b2.save()
28  
-        self.b3 = Book(title='Book 3', pubdate=datetime(2005, 7, 27), author=self.au1)
  27
+        self.b3 = Book(name='Book 3', pubdate=datetime(2005, 7, 27), author=self.au1)
29 28
         self.b3.save()
30  
-        self.b4 = Book(title='Book 4', pubdate=datetime(2005, 7, 28), author=self.au1)
  29
+        self.b4 = Book(name='Book 4', pubdate=datetime(2005, 7, 28), author=self.au1)
31 30
         self.b4.save()
32  
-        self.b5 = Book(title='Book 5', pubdate=datetime(2005, 8, 1, 9, 0), author=self.au2)
  31
+        self.b5 = Book(name='Book 5', pubdate=datetime(2005, 8, 1, 9, 0), author=self.au2)
33 32
         self.b5.save()
34  
-        self.b6 = Book(title='Book 6', pubdate=datetime(2005, 8, 1, 8, 0), author=self.au2)
  33
+        self.b6 = Book(name='Book 6', pubdate=datetime(2005, 8, 1, 8, 0), author=self.au2)
35 34
         self.b6.save()
36  
-        self.b7 = Book(title='Book 7', pubdate=datetime(2005, 7, 27), author=self.au2)
  35
+        self.b7 = Book(name='Book 7', pubdate=datetime(2005, 7, 27), author=self.au2)
37 36
         self.b7.save()
38 37
         # Create a few Tags.
39 38
         self.t1 = Tag(name='Tag 1')
@@ -86,18 +85,18 @@ def test_iterator(self):
86 85
                 'Book 7',
87 86
                 'Book 1',
88 87
             ],
89  
-            transform=attrgetter('title'))
  88
+            transform=attrgetter('name'))
90 89
         # iterator() can be used on any QuerySet.
91 90
         self.assertQuerysetEqual(
92  
-            Book.objects.filter(title__endswith='4').iterator(),
  91
+            Book.objects.filter(name__endswith='4').iterator(),
93 92
             ['Book 4'],
94  
-            transform=attrgetter('title'))
  93
+            transform=attrgetter('name'))
95 94
 
96 95
     def test_count(self):
97 96
         # count() returns the number of objects matching search criteria.
98 97
         self.assertEqual(Book.objects.count(), 7)
99 98
         self.assertEqual(Book.objects.filter(pubdate__exact=datetime(2005, 7, 27)).count(), 3)
100  
-        self.assertEqual(Book.objects.filter(title__startswith='Blah blah').count(), 0)
  99
+        self.assertEqual(Book.objects.filter(name__startswith='Blah blah').count(), 0)
101 100
 
102 101
         # count() should respect sliced query sets.
103 102
         articles = Book.objects.all()
@@ -129,43 +128,43 @@ def test_values(self):
129 128
         # values() returns a list of dictionaries instead of object instances --
130 129
         # and you can specify which fields you want to retrieve.
131 130
         identity = lambda x:x
132  
-        self.assertQuerysetEqual(Book.objects.values('title'),
  131
+        self.assertQuerysetEqual(Book.objects.values('name'),
133 132
             [
134  
-                {'title': 'Book 5'},
135  
-                {'title': 'Book 6'},
136  
-                {'title': 'Book 4'},
137  
-                {'title': 'Book 2'},
138  
-                {'title': 'Book 3'},
139  
-                {'title': 'Book 7'},
140  
-                {'title': 'Book 1'},
  133
+                {'name': 'Book 5'},
  134
+                {'name': 'Book 6'},
  135
+                {'name': 'Book 4'},
  136
+                {'name': 'Book 2'},
  137
+                {'name': 'Book 3'},
  138
+                {'name': 'Book 7'},
  139
+                {'name': 'Book 1'},
141 140
             ],
142 141
             transform=identity)
143 142
         self.assertQuerysetEqual(
144 143
             Book.objects.filter(pubdate__exact=datetime(2005, 7, 27)).values('id'),
145 144
             [{'id': self.b2.id}, {'id': self.b3.id}, {'id': self.b7.id}],
146 145
             transform=identity)
147  
-        self.assertQuerysetEqual(Book.objects.values('id', 'title'),
  146
+        self.assertQuerysetEqual(Book.objects.values('id', 'name'),
148 147
             [
149  
-                {'id': self.b5.id, 'title': 'Book 5'},
150  
-                {'id': self.b6.id, 'title': 'Book 6'},
151  
-                {'id': self.b4.id, 'title': 'Book 4'},
152  
-                {'id': self.b2.id, 'title': 'Book 2'},
153  
-                {'id': self.b3.id, 'title': 'Book 3'},
154  
-                {'id': self.b7.id, 'title': 'Book 7'},
155  
-                {'id': self.b1.id, 'title': 'Book 1'},
  148
+                {'id': self.b5.id, 'name': 'Book 5'},
  149
+                {'id': self.b6.id, 'name': 'Book 6'},
  150
+                {'id': self.b4.id, 'name': 'Book 4'},
  151
+                {'id': self.b2.id, 'name': 'Book 2'},
  152
+                {'id': self.b3.id, 'name': 'Book 3'},
  153
+                {'id': self.b7.id, 'name': 'Book 7'},
  154
+                {'id': self.b1.id, 'name': 'Book 1'},
156 155
             ],
157 156
             transform=identity)
158 157
         # You can use values() with iterator() for memory savings,
159 158
         # because iterator() uses database-level iteration.
160  
-        self.assertQuerysetEqual(Book.objects.values('id', 'title').iterator(),
  159
+        self.assertQuerysetEqual(Book.objects.values('id', 'name').iterator(),
161 160
             [
162  
-                {'title': 'Book 5', 'id': self.b5.id},
163  
-                {'title': 'Book 6', 'id': self.b6.id},
164  
-                {'title': 'Book 4', 'id': self.b4.id},
165  
-                {'title': 'Book 2', 'id': self.b2.id},
166  
-                {'title': 'Book 3', 'id': self.b3.id},
167  
-                {'title': 'Book 7', 'id': self.b7.id},
168  
-                {'title': 'Book 1', 'id': self.b1.id},
  161
+                {'name': 'Book 5', 'id': self.b5.id},
  162
+                {'name': 'Book 6', 'id': self.b6.id},
  163
+                {'name': 'Book 4', 'id': self.b4.id},
  164
+                {'name': 'Book 2', 'id': self.b2.id},
  165
+                {'name': 'Book 3', 'id': self.b3.id},
  166
+                {'name': 'Book 7', 'id': self.b7.id},
  167
+                {'name': 'Book 1', 'id': self.b1.id},
169 168
             ],
170 169
             transform=identity)
171 170
         # The values() method works with "extra" fields specified in extra(select).
@@ -205,39 +204,39 @@ def test_values(self):
205 204
             }], transform=identity)
206 205
         # You can specify fields from forward and reverse relations, just like filter().
207 206
         self.assertQuerysetEqual(
208  
-            Book.objects.values('title', 'author__name'),
  207
+            Book.objects.values('name', 'author__name'),
209 208
             [
210  
-                {'title': self.b5.title, 'author__name': self.au2.name},
211  
-                {'title': self.b6.title, 'author__name': self.au2.name},
212  
-                {'title': self.b4.title, 'author__name': self.au1.name},
213  
-                {'title': self.b2.title, 'author__name': self.au1.name},
214  
-                {'title': self.b3.title, 'author__name': self.au1.name},
215  
-                {'title': self.b7.title, 'author__name': self.au2.name},
216  
-                {'title': self.b1.title, 'author__name': self.au1.name},
  209
+                {'name': self.b5.name, 'author__name': self.au2.name},
  210
+                {'name': self.b6.name, 'author__name': self.au2.name},
  211
+                {'name': self.b4.name, 'author__name': self.au1.name},
  212
+                {'name': self.b2.name, 'author__name': self.au1.name},
  213
+                {'name': self.b3.name, 'author__name': self.au1.name},
  214
+                {'name': self.b7.name, 'author__name': self.au2.name},
  215
+                {'name': self.b1.name, 'author__name': self.au1.name},
217 216
             ], transform=identity)
218 217
         self.assertQuerysetEqual(
219  
-            Author.objects.values('name', 'book__title').order_by('name', 'book__title'),
  218
+            Author.objects.values('name', 'book__name').order_by('name', 'book__name'),
220 219
             [
221  
-                {'name': self.au1.name, 'book__title': self.b1.title},
222  
-                {'name': self.au1.name, 'book__title': self.b2.title},
223  
-                {'name': self.au1.name, 'book__title': self.b3.title},
224  
-                {'name': self.au1.name, 'book__title': self.b4.title},
225  
-                {'name': self.au2.name, 'book__title': self.b5.title},
226  
-                {'name': self.au2.name, 'book__title': self.b6.title},
227  
-                {'name': self.au2.name, 'book__title': self.b7.title},
  220
+                {'name': self.au1.name, 'book__name': self.b1.name},
  221
+                {'name': self.au1.name, 'book__name': self.b2.name},
  222
+                {'name': self.au1.name, 'book__name': self.b3.name},
  223
+                {'name': self.au1.name, 'book__name': self.b4.name},
  224
+                {'name': self.au2.name, 'book__name': self.b5.name},
  225
+                {'name': self.au2.name, 'book__name': self.b6.name},
  226
+                {'name': self.au2.name, 'book__name': self.b7.name},
228 227
             ], transform=identity)
229 228
         self.assertQuerysetEqual(
230  
-            Author.objects.values('name', 'book__title', 'book__tag__name').order_by('name', 'book__title', 'book__tag__name'),
  229
+            Author.objects.values('name', 'book__name', 'book__tag__name').order_by('name', 'book__name', 'book__tag__name'),
231 230
             [
232  
-                {'name': self.au1.name, 'book__title': self.b1.title, 'book__tag__name': self.t1.name},
233  
-                {'name': self.au1.name, 'book__title': self.b2.title, 'book__tag__name': self.t1.name},
234  
-                {'name': self.au1.name, 'book__title': self.b3.title, 'book__tag__name': self.t1.name},
235  
-                {'name': self.au1.name, 'book__title': self.b3.title, 'book__tag__name': self.t2.name},
236  
-                {'name': self.au1.name, 'book__title': self.b4.title, 'book__tag__name': self.t2.name},
237  
-                {'name': self.au2.name, 'book__title': self.b5.title, 'book__tag__name': self.t2.name},
238  
-                {'name': self.au2.name, 'book__title': self.b5.title, 'book__tag__name': self.t3.name},
239  
-                {'name': self.au2.name, 'book__title': self.b6.title, 'book__tag__name': self.t3.name},
240  
-                {'name': self.au2.name, 'book__title': self.b7.title, 'book__tag__name': self.t3.name},
  231
+                {'name': self.au1.name, 'book__name': self.b1.name, 'book__tag__name': self.t1.name},
  232
+                {'name': self.au1.name, 'book__name': self.b2.name, 'book__tag__name': self.t1.name},
  233
+                {'name': self.au1.name, 'book__name': self.b3.name, 'book__tag__name': self.t1.name},
  234
+                {'name': self.au1.name, 'book__name': self.b3.name, 'book__tag__name': self.t2.name},
  235
+                {'name': self.au1.name, 'book__name': self.b4.name, 'book__tag__name': self.t2.name},
  236
+                {'name': self.au2.name, 'book__name': self.b5.name, 'book__tag__name': self.t2.name},
  237
+                {'name': self.au2.name, 'book__name': self.b5.name, 'book__tag__name': self.t3.name},
  238
+                {'name': self.au2.name, 'book__name': self.b6.name, 'book__tag__name': self.t3.name},
  239
+                {'name': self.au2.name, 'book__name': self.b7.name, 'book__tag__name': self.t3.name},
241 240
             ], transform=identity)
242 241
         # However, an exception FieldDoesNotExist will be thrown if you specify
243 242
         # a non-existent field name in values() (a field that is neither in the
@@ -250,7 +249,7 @@ def test_values(self):
250 249
             [{
251 250
                 'id': self.b5.id,
252 251
                 'author_id': self.au2.id,
253  
-                'title': 'Book 5',
  252
+                'name': 'Book 5',
254 253
                 'pages': 0,
255 254
                 'pubdate': datetime(2005, 8, 1, 9, 0)
256 255
             }], transform=identity)
@@ -261,7 +260,7 @@ def test_values_list(self):
261 260
         # Within each tuple, the order of the elements is the same as the order
262 261
         # of fields in the values_list() call.
263 262
         identity = lambda x:x
264  
-        self.assertQuerysetEqual(Book.objects.values_list('title'),
  263
+        self.assertQuerysetEqual(Book.objects.values_list('name'),
265 264
             [
266 265
                 ('Book 5',),
267 266
                 ('Book 6',),
@@ -310,19 +309,19 @@ def test_values_list(self):
310 309
             ],
311 310
             transform=identity)
312 311
         self.assertQuerysetEqual(
313  
-            Author.objects.values_list('name', 'book__title', 'book__tag__name').order_by('name', 'book__title', 'book__tag__name'),
  312
+            Author.objects.values_list('name', 'book__name', 'book__tag__name').order_by('name', 'book__name', 'book__tag__name'),
314 313
             [
315  
-                (self.au1.name, self.b1.title, self.t1.name),
316  
-                (self.au1.name, self.b2.title, self.t1.name),
317  
-                (self.au1.name, self.b3.title, self.t1.name),
318  
-                (self.au1.name, self.b3.title, self.t2.name),
319  
-                (self.au1.name, self.b4.title, self.t2.name),
320  
-                (self.au2.name, self.b5.title, self.t2.name),
321  
-                (self.au2.name, self.b5.title, self.t3.name),
322  
-                (self.au2.name, self.b6.title, self.t3.name),
323  
-                (self.au2.name, self.b7.title, self.t3.name),
  314
+                (self.au1.name, self.b1.name, self.t1.name),
  315
+                (self.au1.name, self.b2.name, self.t1.name),
  316
+                (self.au1.name, self.b3.name, self.t1.name),
  317
+                (self.au1.name, self.b3.name, self.t2.name),
  318
+                (self.au1.name, self.b4.name, self.t2.name),
  319
+                (self.au2.name, self.b5.name, self.t2.name),
  320
+                (self.au2.name, self.b5.name, self.t3.name),
  321
+                (self.au2.name, self.b6.name, self.t3.name),
  322
+                (self.au2.name, self.b7.name, self.t3.name),
324 323
             ], transform=identity)
325  
-        self.assertRaises(TypeError, Book.objects.values_list, 'id', 'title', flat=True)
  324
+        self.assertRaises(TypeError, Book.objects.values_list, 'id', 'name', flat=True)
326 325
 
327 326
     def test_get_next_previous_by(self):
328 327
         # Every DateField and DateTimeField creates get_next_by_FOO() and
@@ -333,7 +332,7 @@ def test_get_next_previous_by(self):
333 332
                          '<Book: Book 2>')
334 333
         self.assertEqual(repr(self.b2.get_next_by_pubdate()),
335 334
                          '<Book: Book 3>')
336  
-        self.assertEqual(repr(self.b2.get_next_by_pubdate(title__endswith='6')),
  335
+        self.assertEqual(repr(self.b2.get_next_by_pubdate(name__endswith='6')),
337 336
                          '<Book: Book 6>')
338 337
         self.assertEqual(repr(self.b3.get_next_by_pubdate()),
339 338
                          '<Book: Book 7>')
@@ -361,9 +360,9 @@ def test_get_next_previous_by(self):
361 360
     def test_escaping(self):
362 361
         # Underscores, percent signs and backslashes have special meaning in the
363 362
         # underlying SQL code, but Django handles the quoting of them automatically.
364  
-        b8 = Book(title='Book_ with underscore', pubdate=datetime(2005, 11, 20))
  363
+        b8 = Book(name='Book_ with underscore', pubdate=datetime(2005, 11, 20))
365 364
         b8.save()
366  
-        self.assertQuerysetEqual(Book.objects.filter(title__startswith='Book'),
  365
+        self.assertQuerysetEqual(Book.objects.filter(name__startswith='Book'),
367 366
             [
368 367
                 '<Book: Book_ with underscore>',
369 368
                 '<Book: Book 5>',
@@ -374,11 +373,11 @@ def test_escaping(self):
374 373
                 '<Book: Book 7>',
375 374
                 '<Book: Book 1>',
376 375
             ])
377  
-        self.assertQuerysetEqual(Book.objects.filter(title__startswith='Book_'),
  376
+        self.assertQuerysetEqual(Book.objects.filter(name__startswith='Book_'),
378 377
                                  ['<Book: Book_ with underscore>'])
379  
-        b9 = Book(title='Book% with percent sign', pubdate=datetime(2005, 11, 21))
  378
+        b9 = Book(name='Book% with percent sign', pubdate=datetime(2005, 11, 21))
380 379
         b9.save()
381  
-        self.assertQuerysetEqual(Book.objects.filter(title__startswith='Book'),
  380
+        self.assertQuerysetEqual(Book.objects.filter(name__startswith='Book'),
382 381
             [
383 382
                 '<Book: Book% with percent sign>',
384 383
                 '<Book: Book_ with underscore>',
@@ -390,21 +389,21 @@ def test_escaping(self):
390 389
                 '<Book: Book 7>',
391 390
                 '<Book: Book 1>',
392 391
             ])
393  
-        self.assertQuerysetEqual(Book.objects.filter(title__startswith='Book%'),
  392
+        self.assertQuerysetEqual(Book.objects.filter(name__startswith='Book%'),
394 393
                                  ['<Book: Book% with percent sign>'])
395  
-        b10 = Book(title='Book with \\ backslash', pubdate=datetime(2005, 11, 22))
  394
+        b10 = Book(name='Book with \\ backslash', pubdate=datetime(2005, 11, 22))
396 395
         b10.save()
397  
-        self.assertQuerysetEqual(Book.objects.filter(title__contains='\\'),
  396
+        self.assertQuerysetEqual(Book.objects.filter(name__contains='\\'),
398 397
                                  ['<Book: Book with \ backslash>'])
399 398
 
400 399
     def test_exclude(self):
401  
-        b8 = Book.objects.create(title='Book_ with underscore', pubdate=datetime(2005, 11, 20))
402  
-        b9 = Book.objects.create(title='Book% with percent sign', pubdate=datetime(2005, 11, 21))
403  
-        b10 = Book.objects.create(title='Book with \\ backslash', pubdate=datetime(2005, 11, 22))
  400
+        b8 = Book.objects.create(name='Book_ with underscore', pubdate=datetime(2005, 11, 20))
  401
+        b9 = Book.objects.create(name='Book% with percent sign', pubdate=datetime(2005, 11, 21))
  402
+        b10 = Book.objects.create(name='Book with \\ backslash', pubdate=datetime(2005, 11, 22))
404 403
 
405 404
         # exclude() is the opposite of filter() when doing lookups:
406 405
         self.assertQuerysetEqual(
407  
-            Book.objects.filter(title__contains='Book').exclude(title__contains='with'),
  406
+            Book.objects.filter(name__contains='Book').exclude(name__contains='with'),
408 407
             [
409 408
                 '<Book: Book 5>',
410 409
                 '<Book: Book 6>',
@@ -414,7 +413,7 @@ def test_exclude(self):
414 413
                 '<Book: Book 7>',
415 414
                 '<Book: Book 1>',
416 415
             ])
417  
-        self.assertQuerysetEqual(Book.objects.exclude(title__startswith="Book_"),
  416
+        self.assertQuerysetEqual(Book.objects.exclude(name__startswith="Book_"),
418 417
             [
419 418
                 '<Book: Book with \\ backslash>',
420 419
                 '<Book: Book% with percent sign>',
@@ -426,7 +425,7 @@ def test_exclude(self):
426 425
                 '<Book: Book 7>',
427 426
                 '<Book: Book 1>',
428 427
             ])
429  
-        self.assertQuerysetEqual(Book.objects.exclude(title="Book 7"),
  428
+        self.assertQuerysetEqual(Book.objects.exclude(name="Book 7"),
430 429
             [
431 430
                 '<Book: Book with \\ backslash>',
432 431
                 '<Book: Book% with percent sign>',
@@ -443,12 +442,12 @@ def test_none(self):
443 442
        # none() returns a QuerySet that behaves like any other QuerySet object
444 443
         self.assertQuerysetEqual(Book.objects.none(), [])
445 444
         self.assertQuerysetEqual(
446  
-            Book.objects.none().filter(title__startswith='Book'), [])
  445
+            Book.objects.none().filter(name__startswith='Book'), [])
447 446
         self.assertQuerysetEqual(
448  
-            Book.objects.filter(title__startswith='Book').none(), [])
  447
+            Book.objects.filter(name__startswith='Book').none(), [])
449 448
         self.assertEqual(Book.objects.none().count(), 0)
450 449
         self.assertEqual(
451  
-            Book.objects.none().update(title="This should not take effect"), 0)
  450
+            Book.objects.none().update(name="This should not take effect"), 0)
452 451
         self.assertQuerysetEqual(
453 452
             [article for article in Book.objects.none().iterator()],
454 453
             [])
@@ -469,41 +468,46 @@ def test_in(self):
469 468
 
470 469
     def test_error_messages(self):
471 470
         # Programming errors are pointed out with nice error messages
472  
-        with six.assertRaisesRegex(self, FieldError, "Cannot resolve keyword 'pubdate_year' "
473  
-             "into field. Choices are: .+"):
474  
-                Book.objects.filter(pubdate_year='2005').count()
475  
-
476  
-        with self.assertRaises(FieldError, msg="Join on field 'title' not permitted. "
477  
-             "Did you misspell 'starts' for the lookup type?"):
478  
-                Book.objects.filter(title__starts='Book')
  471
+        try:
  472
+            Book.objects.filter(pubdate_year='2005').count()
  473
+            self.fail('FieldError not raised')
  474
+        except FieldError as ex:
  475
+            self.assertEqual(str(ex), "Cannot resolve keyword 'pubdate_year' "
  476
+                             "into field. Choices are: author, id, name, pages, pubdate, tag, tags")
  477
+        try:
  478
+            Book.objects.filter(name__starts='Book')
  479
+            self.fail('FieldError not raised')
  480
+        except FieldError as ex:
  481
+            self.assertEqual(str(ex), "Join on field 'name' not permitted. "
  482
+                             "Did you misspell 'starts' for the lookup type?")
479 483
 
480 484
     def test_regex(self):
481 485
         # Create some articles with a bit more interesting names for testing field lookups:
482 486
         for a in Book.objects.all():
483 487
             a.delete()
484 488
         now = datetime.now()
485  
-        b1 = Book(pubdate=now, title='f')
  489
+        b1 = Book(pubdate=now, name='f')
486 490
         b1.save()
487  
-        b2 = Book(pubdate=now, title='fo')
  491
+        b2 = Book(pubdate=now, name='fo')
488 492
         b2.save()
489  
-        b3 = Book(pubdate=now, title='foo')
  493
+        b3 = Book(pubdate=now, name='foo')
490 494
         b3.save()
491  
-        b4 = Book(pubdate=now, title='fooo')
  495
+        b4 = Book(pubdate=now, name='fooo')
492 496
         b4.save()
493  
-        b5 = Book(pubdate=now, title='hey-Foo')
  497
+        b5 = Book(pubdate=now, name='hey-Foo')
494 498
         b5.save()
495  
-        b6 = Book(pubdate=now, title='bar')
  499
+        b6 = Book(pubdate=now, name='bar')
496 500
         b6.save()
497  
-        b7 = Book(pubdate=now, title='AbBa')
  501
+        b7 = Book(pubdate=now, name='AbBa')
498 502
         b7.save()
499  
-        b8 = Book(pubdate=now, title='baz')
  503
+        b8 = Book(pubdate=now, name='baz')
500 504
         b8.save()
501  
-        b9 = Book(pubdate=now, title='baxZ')
  505
+        b9 = Book(pubdate=now, name='baxZ')
502 506
         b9.save()
503 507
         # zero-or-more
504  
-        self.assertQuerysetEqual(Book.objects.filter(title__regex=r'fo*'),
  508
+        self.assertQuerysetEqual(Book.objects.filter(name__regex=r'fo*'),
505 509
             ['<Book: f>', '<Book: fo>', '<Book: foo>', '<Book: fooo>'])
506  
-        self.assertQuerysetEqual(Book.objects.filter(title__iregex=r'fo*'),
  510
+        self.assertQuerysetEqual(Book.objects.filter(name__iregex=r'fo*'),
507 511
             [
508 512
                 '<Book: f>',
509 513
                 '<Book: fo>',
@@ -512,54 +516,54 @@ def test_regex(self):
512 516
                 '<Book: hey-Foo>',
513 517
             ])
514 518
         # one-or-more
515  
-        self.assertQuerysetEqual(Book.objects.filter(title__regex=r'fo+'),
  519
+        self.assertQuerysetEqual(Book.objects.filter(name__regex=r'fo+'),
516 520
             ['<Book: fo>', '<Book: foo>', '<Book: fooo>'])
517 521
         # wildcard
518  
-        self.assertQuerysetEqual(Book.objects.filter(title__regex=r'fooo?'),
  522
+        self.assertQuerysetEqual(Book.objects.filter(name__regex=r'fooo?'),
519 523
             ['<Book: foo>', '<Book: fooo>'])
520 524
         # leading anchor
521  
-        self.assertQuerysetEqual(Book.objects.filter(title__regex=r'^b'),
  525
+        self.assertQuerysetEqual(Book.objects.filter(name__regex=r'^b'),
522 526
             ['<Book: bar>', '<Book: baxZ>', '<Book: baz>'])
523  
-        self.assertQuerysetEqual(Book.objects.filter(title__iregex=r'^a'),
  527
+        self.assertQuerysetEqual(Book.objects.filter(name__iregex=r'^a'),
524 528
             ['<Book: AbBa>'])
525 529
         # trailing anchor
526  
-        self.assertQuerysetEqual(Book.objects.filter(title__regex=r'z$'),
  530
+        self.assertQuerysetEqual(Book.objects.filter(name__regex=r'z$'),
527 531
             ['<Book: baz>'])
528  
-        self.assertQuerysetEqual(Book.objects.filter(title__iregex=r'z$'),
  532
+        self.assertQuerysetEqual(Book.objects.filter(name__iregex=r'z$'),
529 533
             ['<Book: baxZ>', '<Book: baz>'])
530 534
         # character sets
531  
-        self.assertQuerysetEqual(Book.objects.filter(title__regex=r'ba[rz]'),
  535
+        self.assertQuerysetEqual(Book.objects.filter(name__regex=r'ba[rz]'),
532 536
             ['<Book: bar>', '<Book: baz>'])
533  
-        self.assertQuerysetEqual(Book.objects.filter(title__regex=r'ba.[RxZ]'),
  537
+        self.assertQuerysetEqual(Book.objects.filter(name__regex=r'ba.[RxZ]'),
534 538
             ['<Book: baxZ>'])
535  
-        self.assertQuerysetEqual(Book.objects.filter(title__iregex=r'ba[RxZ]'),
  539
+        self.assertQuerysetEqual(Book.objects.filter(name__iregex=r'ba[RxZ]'),
536 540
             ['<Book: bar>', '<Book: baxZ>', '<Book: baz>'])
537 541
 
538 542
         # and more articles:
539  
-        b10 = Book(pubdate=now, title='foobar')
  543
+        b10 = Book(pubdate=now, name='foobar')
540 544
         b10.save()
541  
-        b11 = Book(pubdate=now, title='foobaz')
  545
+        b11 = Book(pubdate=now, name='foobaz')
542 546
         b11.save()
543  
-        b12 = Book(pubdate=now, title='ooF')
  547
+        b12 = Book(pubdate=now, name='ooF')
544 548
         b12.save()
545  
-        b13 = Book(pubdate=now, title='foobarbaz')
  549
+        b13 = Book(pubdate=now, name='foobarbaz')
546 550
         b13.save()
547  
-        b14 = Book(pubdate=now, title='zoocarfaz')
  551
+        b14 = Book(pubdate=now, name='zoocarfaz')
548 552
         b14.save()
549  
-        b15 = Book(pubdate=now, title='barfoobaz')
  553
+        b15 = Book(pubdate=now, name='barfoobaz')
550 554
         b15.save()
551  
-        b16 = Book(pubdate=now, title='bazbaRFOO')
  555
+        b16 = Book(pubdate=now, name='bazbaRFOO')
552 556
         b16.save()
553 557
 
554 558
         # alternation
555  
-        self.assertQuerysetEqual(Book.objects.filter(title__regex=r'oo(f|b)'),
  559
+        self.assertQuerysetEqual(Book.objects.filter(name__regex=r'oo(f|b)'),
556 560
             [
557 561
                 '<Book: barfoobaz>',
558 562
                 '<Book: foobar>',
559 563
                 '<Book: foobarbaz>',
560 564
                 '<Book: foobaz>',
561 565
             ])
562  
-        self.assertQuerysetEqual(Book.objects.filter(title__iregex=r'oo(f|b)'),
  566
+        self.assertQuerysetEqual(Book.objects.filter(name__iregex=r'oo(f|b)'),
563 567
             [
564 568
                 '<Book: barfoobaz>',
565 569
                 '<Book: foobar>',
@@ -567,11 +571,11 @@ def test_regex(self):
567 571
                 '<Book: foobaz>',
568 572
                 '<Book: ooF>',
569 573
             ])
570  
-        self.assertQuerysetEqual(Book.objects.filter(title__regex=r'^foo(f|b)'),
  574
+        self.assertQuerysetEqual(Book.objects.filter(name__regex=r'^foo(f|b)'),
571 575
             ['<Book: foobar>', '<Book: foobarbaz>', '<Book: foobaz>'])
572 576
 
573 577
         # greedy matching
574  
-        self.assertQuerysetEqual(Book.objects.filter(title__regex=r'b.*az'),
  578
+        self.assertQuerysetEqual(Book.objects.filter(name__regex=r'b.*az'),
575 579
             [
576 580
                 '<Book: barfoobaz>',
577 581
                 '<Book: baz>',
@@ -579,7 +583,7 @@ def test_regex(self):
579 583
                 '<Book: foobarbaz>',
580 584
                 '<Book: foobaz>',
581 585
             ])
582  
-        self.assertQuerysetEqual(Book.objects.filter(title__iregex=r'b.*ar'),
  586
+        self.assertQuerysetEqual(Book.objects.filter(name__iregex=r'b.*ar'),
583 587
             [
584 588
                 '<Book: bar>',
585 589
                 '<Book: barfoobaz>',
@@ -592,21 +596,21 @@ def test_regex(self):
592 596
     def test_regex_backreferencing(self):
593 597
         # grouping and backreferences
594 598
         now = datetime.now()
595  
-        b10 = Book(pubdate=now, title='foobar')
  599
+        b10 = Book(pubdate=now, name='foobar')
596 600
         b10.save()
597  
-        b11 = Book(pubdate=now, title='foobaz')
  601
+        b11 = Book(pubdate=now, name='foobaz')
598 602
         b11.save()
599  
-        b12 = Book(pubdate=now, title='ooF')
  603
+        b12 = Book(pubdate=now, name='ooF')
600 604
         b12.save()
601  
-        b13 = Book(pubdate=now, title='foobarbaz')
  605
+        b13 = Book(pubdate=now, name='foobarbaz')
602 606
         b13.save()
603  
-        b14 = Book(pubdate=now, title='zoocarfaz')
  607
+        b14 = Book(pubdate=now, name='zoocarfaz')
604 608
         b14.save()
605  
-        b15 = Book(pubdate=now, title='barfoobaz')
  609
+        b15 = Book(pubdate=now, name='barfoobaz')
606 610
         b15.save()
607  
-        b16 = Book(pubdate=now, title='bazbaRFOO')
  611
+        b16 = Book(pubdate=now, name='bazbaRFOO')
608 612
         b16.save()
609  
-        self.assertQuerysetEqual(Book.objects.filter(title__regex=r'b(.).*b\1'),
  613
+        self.assertQuerysetEqual(Book.objects.filter(name__regex=r'b(.).*b\1'),
610 614
             ['<Book: barfoobaz>', '<Book: bazbaRFOO>', '<Book: foobarbaz>'])
611 615
 
612 616
     def test_nonfield_lookups(self):
27  tests/model_forms/models.py
@@ -17,7 +17,6 @@
17 17
 from django.utils import six
18 18
 from django.utils.encoding import python_2_unicode_compatible
19 19
 
20  
-from shared_models.models import Author, Book
21 20
 
22 21
 temp_storage_dir = tempfile.mkdtemp(dir=os.environ['DJANGO_TEST_TEMP_DIR'])
23 22
 temp_storage = FileSystemStorage(temp_storage_dir)
@@ -47,12 +46,22 @@ def __repr__(self):
47 46
         return self.__str__()
48 47
 
49 48
 @python_2_unicode_compatible
  49
+class Writer(models.Model):
  50
+    name = models.CharField(max_length=50, help_text='Use both first and last names.')
  51
+
  52
+    class Meta:
  53
+        ordering = ('name',)
  54
+
  55
+    def __str__(self):
  56
+        return self.name
  57
+
  58
+@python_2_unicode_compatible
50 59
 class Article(models.Model):
51 60
     headline = models.CharField(max_length=50)
52 61
     slug = models.SlugField()
53 62
     pub_date = models.DateField()
54 63
     created = models.DateField(editable=False)
55  
-    writer = models.ForeignKey(Author)
  64
+    writer = models.ForeignKey(Writer)
56 65
     article = models.TextField()
57 66
     categories = models.ManyToManyField(Category, blank=True)
58 67
     status = models.PositiveIntegerField(choices=ARTICLE_STATUS, blank=True, null=True)
@@ -72,12 +81,12 @@ class ImprovedArticle(models.Model):
72 81
 class ImprovedArticleWithParentLink(models.Model):
73 82
     article = models.OneToOneField(Article, parent_link=True)
74 83
 
75  
-class BetterAuthor(Author):
  84
+class BetterWriter(Writer):
76 85
     score = models.IntegerField()
77 86
 
78 87
 @python_2_unicode_compatible
79  
-class AuthorProfile(models.Model):
80  
-    writer = models.OneToOneField(Author, primary_key=True)
  88
+class WriterProfile(models.Model):
  89
+    writer = models.OneToOneField(Writer, primary_key=True)
81 90
     age = models.PositiveIntegerField()
82 91
 
83 92
     def __str__(self):
@@ -177,6 +186,14 @@ def __str__(self):
177 186
     def __repr__(self):
178 187
         return self.__str__()
179 188
 
  189
+class Book(models.Model):
  190
+    title = models.CharField(max_length=40)
  191
+    author = models.ForeignKey(Writer, blank=True, null=True)
  192
+    special_id = models.IntegerField(blank=True, null=True, unique=True)
  193
+
  194
+    class Meta:
  195
+        unique_together = ('title', 'author')
  196
+
180 197
 class BookXtra(models.Model):
181 198
     isbn = models.CharField(max_length=16, unique=True)
182 199
     suffix1 = models.IntegerField(blank=True, default=0)
89  tests/model_forms/tests.py
@@ -17,13 +17,11 @@
17 17
 from django.test import TestCase
18 18
 from django.utils import six
19 19
 
20  
-from shared_models.models import Author, Book
21  
-
22  
-from .models import (Article, ArticleStatus, BetterAuthor, BigInt,
  20
+from .models import (Article, ArticleStatus, BetterWriter, BigInt, Book,
23 21
     Category, CommaSeparatedInteger, CustomFieldForExclusionModel, DerivedBook,
24 22
     DerivedPost, ExplicitPK, FlexibleDatePost, ImprovedArticle,
25 23
     ImprovedArticleWithParentLink, Inventory, Post, Price,
26  
-    Product, TextFile, AuthorProfile, Colour, ColourfulItem,
  24
+    Product, TextFile, Writer, WriterProfile, Colour, ColourfulItem,
27 25
     ArticleStatusNote, DateTimePost, test_images)
28 26
 
29 27
 if test_images:
@@ -54,13 +52,11 @@ class Meta:
54 52
 
55 53
 class BookForm(forms.ModelForm):
56 54
     class Meta:
57  
-        fields = ['title', 'author', 'pubdate']
58  
-        model = Book
  55
+       model = Book
59 56
 
60 57
 
61 58
 class DerivedBookForm(forms.ModelForm):
62 59
     class Meta:
63  
-        fields = ['title', 'author', 'isbn', 'suffix1', 'suffix2']
64 60
         model = DerivedBook
65 61
 
66 62
 
@@ -88,11 +84,11 @@ class Meta:
88 84
         fields = '__all__'
89 85
 
90 86
 
91  
-class CustomAuthorForm(forms.ModelForm):
  87
+class CustomWriterForm(forms.ModelForm):
92 88
    name = forms.CharField(required=False)
93 89
 
94 90
    class Meta:
95  
-       model = Author
  91
+       model = Writer
96 92
        fields = '__all__'
97 93
 
98 94
 
@@ -128,7 +124,7 @@ class Meta:
128 124
 
129 125
 class RoykoForm(forms.ModelForm):
130 126
     class Meta:
131  
-        model = Author
  127
+        model = Writer
132 128
         fields = '__all__'
133 129
 
134 130
 
@@ -188,15 +184,14 @@ class Meta:
188 184
         fields = '__all__'
189 185
 
190 186
 
191  
-class BetterAuthorForm(forms.ModelForm):
  187
+class BetterWriterForm(forms.ModelForm):
192 188
     class Meta:
193  
-        model = BetterAuthor
  189
+        model = BetterWriter
194 190
         fields = '__all__'
195 191
 
196  
-
197  
-class AuthorProfileForm(forms.ModelForm):
  192
+class WriterProfileForm(forms.ModelForm):
198 193
     class Meta:
199  
-        model = AuthorProfile
  194
+        model = WriterProfile
200 195
         fields = '__all__'
201 196
 
202 197
 
@@ -324,14 +319,14 @@ class Meta:
324 319
                                      forms.fields.BooleanField)
325 320
 
326 321
     def test_override_field(self):
327  
-        class AuthorForm(forms.ModelForm):
  322
+        class WriterForm(forms.ModelForm):
328 323
             book = forms.CharField(required=False)
329 324
 
330 325
             class Meta:
331  
-                model = Author
  326
+                model = Writer
332 327
                 fields = '__all__'
333 328
 
334  
-        wf = AuthorForm({'name': 'Richard Lockridge'})
  329
+        wf = WriterForm({'name': 'Richard Lockridge'})
335 330
         self.assertTrue(wf.is_valid())
336 331
 
337 332
     def test_limit_nonexistent_field(self):
@@ -556,7 +551,7 @@ def test_validates_with_replaced_field_excluded(self):
556 551
         assert form.is_valid()
557 552
 
558 553
     def test_notrequired_overrides_notblank(self):
559  
-        form = CustomAuthorForm({})
  554
+        form = CustomWriterForm({})
560 555
         assert form.is_valid()
561 556
 
562 557
 
@@ -565,7 +560,7 @@ def test_notrequired_overrides_notblank(self):
565 560
 # unique/unique_together validation
566 561
 class UniqueTest(TestCase):
567 562
     def setUp(self):
568  
-        self.author = Author.objects.create(name='Mike Royko')
  563
+        self.writer = Writer.objects.create(name='Mike Royko')
569 564
 
570 565
     def test_simple_unique(self):
571 566
         form = ProductForm({'slug': 'teddy-bear-blue'})
@@ -589,31 +584,33 @@ def test_unique_together(self):
589 584
 
590 585
     def test_unique_null(self):
591 586
         title = 'I May Be Wrong But I Doubt It'
592  
-        form = BookForm({'title': title, 'author': self.author.pk, 'pubdate': '2012-12-12 00:00:00'})
  587
+        form = BookForm({'title': title, 'author': self.writer.pk})
593 588
         self.assertTrue(form.is_valid())
594 589
         form.save()
595  
-        form = BookForm({'title': title, 'author': self.author.pk, 'pubdate': '2012-12-12 00:00:00'})
  590
+        form = BookForm({'title': title, 'author': self.writer.pk})
596 591
         self.assertFalse(form.is_valid())
597 592
         self.assertEqual(len(form.errors), 1)
598 593
         self.assertEqual(form.errors['__all__'], ['Book with this Title and Author already exists.'])
599  
-        form = BookForm({'title': title, 'pubdate': '2012-12-12 00:00:00'})
  594
+        form = BookForm({'title': title})
600 595
         self.assertTrue(form.is_valid())
601 596
         form.save()
602  
-        form = BookForm({'title': title, 'pubdate': '2012-12-12 00:00:00'})
  597
+        form = BookForm({'title': title})
603 598
         self.assertTrue(form.is_valid())
604 599
 
605 600
     def test_inherited_unique(self):
606  
-        form = BetterAuthorForm({'name': 'Mike Royko', 'score': 3})
  601
+        title = 'Boss'
  602
+        Book.objects.create(title=title, author=self.writer, special_id=1)
  603
+        form = DerivedBookForm({'title': 'Other', 'author': self.writer.pk, 'special_id': '1', 'isbn': '12345'})
607 604
         self.assertFalse(form.is_valid())
608 605
         self.assertEqual(len(form.errors), 1)
609  
-        self.assertEqual(form.errors['name'], ['Author with this Name already exists.'])
  606
+        self.assertEqual(form.errors['special_id'], ['Book with this Special id already exists.'])
610 607
 
611 608
     def test_inherited_unique_together(self):
612 609
         title = 'Boss'
613  
-        form = BookForm({'title': title, 'author': self.author.pk, 'pubdate': '2012-12-12 00:00:00'})
  610
+        form = BookForm({'title': title, 'author': self.writer.pk})
614 611
         self.assertTrue(form.is_valid())
615 612
         form.save()
616  
-        form = DerivedBookForm({'title': title, 'author': self.author.pk, 'isbn': '12345'})
  613
+        form = DerivedBookForm({'title': title, 'author': self.writer.pk, 'isbn': '12345'})
617 614
         self.assertFalse(form.is_valid())
618 615
         self.assertEqual(len(form.errors), 1)
619 616
         self.assertEqual(form.errors['__all__'], ['Book with this Title and Author already exists.'])
@@ -621,9 +618,8 @@ def test_inherited_unique_together(self):
621 618
     def test_abstract_inherited_unique(self):
622 619
         title = 'Boss'
623 620
         isbn = '12345'
624  
-        dbook = DerivedBook.objects.create(title=title, author=self.author, isbn=isbn,
625  
-            pubdate='2012-12-12 00:00')
626  
-        form = DerivedBookForm({'title': 'Other', 'author': self.author.pk, 'isbn': isbn})
  621
+        dbook = DerivedBook.objects.create(title=title, author=self.writer, isbn=isbn)
  622
+        form = DerivedBookForm({'title': 'Other', 'author': self.writer.pk, 'isbn': isbn})
627 623
         self.assertFalse(form.is_valid())
628 624
         self.assertEqual(len(form.errors), 1)
629 625
         self.assertEqual(form.errors['isbn'], ['Derived book with this Isbn already exists.'])
@@ -631,11 +627,10 @@ def test_abstract_inherited_unique(self):
631 627
     def test_abstract_inherited_unique_together(self):
632 628
         title = 'Boss'
633 629
         isbn = '12345'
634  
-        dbook = DerivedBook.objects.create(title=title, author=self.author, isbn=isbn,
635  
-            pubdate='2012-12-12 00:00')
  630
+        dbook = DerivedBook.objects.create(title=title, author=self.writer, isbn=isbn)
636 631
         form = DerivedBookForm({
637 632
                     'title': 'Other',
638  
-                    'author': self.author.pk,
  633
+                    'author': self.writer.pk,
639 634
                     'isbn': '9876',
640 635
                     'suffix1': '0',
641 636
                     'suffix2': '0'
@@ -753,7 +748,7 @@ def test_model_to_dict_many_to_many(self):
753 748
         ]
754 749
         for c in categories:
755 750
             c.save()
756  
-        writer = Author(name='Test writer')
  751
+        writer = Writer(name='Test writer')
757 752
         writer.save()
758 753
 
759 754
         art = Article(
@@ -862,10 +857,10 @@ def test_with_data(self):
862 857
         with self.assertRaises(ValueError):
863 858
             f.save()
864 859
 
865  
-        # Create a couple of Authors.
866  
-        w_royko = Author(name='Mike Royko')
  860
+        # Create a couple of Writers.
  861
+        w_royko = Writer(name='Mike Royko')
867 862
         w_royko.save()
868  
-        w_woodward = Author(name='Bob Woodward')
  863
+        w_woodward = Writer(name='Bob Woodward')
869 864
         w_woodward.save()
870 865
         # ManyToManyFields are represented by a MultipleChoiceField, ForeignKeys and any
871 866
         # fields with the 'choices' attribute are represented by a ChoiceField.
@@ -903,9 +898,9 @@ def test_with_data(self):
903 898
 
904 899
         # When the ModelForm is passed an instance, that instance's current values are
905 900
         # inserted as 'initial' data in each Field.
906  
-        w = Author.objects.get(name='Mike Royko')
  901
+        w = Writer.objects.get(name='Mike Royko')
907 902
         f = RoykoForm(auto_id=False, instance=w)
908  
-        self.assertHTMLEqual(six.text_type(f), '''<tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="100" /><br /><span class="helptext">Use both first and last names.</span></td></tr>''')
  903
+        self.assertHTMLEqual(six.text_type(f), '''<tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br /><span class="helptext">Use both first and last names.</span></td></tr>''')
909 904
 
910 905
         art = Article(
911 906
                     headline='Test article',
@@ -1117,7 +1112,7 @@ def test_with_data(self):
1117 1112
 
1118 1113
         c4 = Category.objects.create(name='Fourth', url='4th')
1119 1114
         self.assertEqual(c4.name, 'Fourth')
1120  
-        w_bernstein = Author.objects.create(name='Carl Bernstein')
  1115
+        w_bernstein = Writer.objects.create(name='Carl Bernstein')
1121 1116
         self.assertEqual(w_bernstein.name, 'Carl Bernstein')
1122 1117
         self.assertHTMLEqual(f.as_ul(), '''<li>Headline: <input type="text" name="headline" maxlength="50" /></li>
1123 1118
 <li>Slug: <input type="text" name="slug" maxlength="50" /></li>
@@ -1294,17 +1289,17 @@ def test_with_data(self):
1294 1289
 
1295 1290
         self.assertEqual(list(ImprovedArticleWithParentLinkForm.base_fields), [])
1296 1291
 
1297  
-        bw = BetterAuthor(name='Joe Better', score=10)
  1292
+        bw = BetterWriter(name='Joe Better', score=10)
1298 1293
         bw.save()
1299 1294
         self.assertEqual(sorted(model_to_dict(bw)),
1300  
-                         ['author_ptr', 'id', 'name', 'score'])
  1295
+                         ['id', 'name', 'score', 'writer_ptr'])
1301 1296
 
1302  
-        form = BetterAuthorForm({'name': 'Some Name', 'score': 12})
  1297
+        form = BetterWriterForm({'name': 'Some Name', 'score': 12})
1303 1298
         self.assertEqual(form.is_valid(), True)
1304 1299
         bw2 = form.save()
1305 1300
         bw2.delete()
1306 1301
 
1307  
-        form = AuthorProfileForm()
  1302
+        form = WriterProfileForm()
1308 1303
         self.assertHTMLEqual(form.as_p(), '''<p><label for="id_writer">Writer:</label> <select name="writer" id="id_writer">
1309 1304
 <option value="" selected="selected">---------</option>
1310 1305
 <option value="%s">Bob Woodward</option>
@@ -1318,11 +1313,11 @@ def test_with_data(self):
1318 1313
             'writer': six.text_type(w_woodward.pk),
1319 1314
             'age': '65',
1320 1315
         }
1321  
-        form = AuthorProfileForm(data)
  1316
+        form = WriterProfileForm(data)
1322 1317
         instance = form.save()
1323 1318
         self.assertEqual(six.text_type(instance), 'Bob Woodward is 65')
1324 1319
 
1325  
-        form = AuthorProfileForm(instance=instance)
  1320
+        form = WriterProfileForm(instance=instance)
1326 1321
         self.assertHTMLEqual(form.as_p(), '''<p><label for="id_writer">Writer:</label> <select name="writer" id="id_writer">
1327 1322
 <option value="">---------</option>
1328 1323
 <option value="%s" selected="selected">Bob Woodward</option>
17  tests/shared_models/models.py
... ...
@@ -1,5 +1,3 @@
1  
-from __future__ import unicode_literals
2  
-
3 1
 from django.db import models
4 2
 from django.utils import timezone
5 3
 from django.utils.encoding import python_2_unicode_compatible
@@ -11,11 +9,7 @@ class Tag(models.Model):
11 9
 
12 10
 @python_2_unicode_compatible
13 11
 class Author(models.Model):
14  
-    name = models.CharField(max_length=100, help_text='Use both first and last names.',
15  
-        unique=True)
16  
-
17  
-    class Meta:
18  
-        ordering = ['name']
  12
+    name = models.CharField(max_length=100)
19 13
 
20 14
     def __str__(self):
21 15
         return self.name
@@ -23,15 +17,14 @@ def __str__(self):
23 17
 
24 18
 @python_2_unicode_compatible
25 19
 class Book(models.Model):
26  
-    title = models.CharField(max_length=200)
  20
+    name = models.CharField(max_length=200)
27 21
     pages = models.IntegerField(default=0)
28  
-    author = models.ForeignKey(Author, null=True, blank=True)
  22
+    author = models.ForeignKey(Author, null=True)
29 23
     pubdate = models.DateTimeField()
30 24
     tags = models.ManyToManyField(Tag)
31 25
 
32 26
     class Meta:
33  
-        ordering = ['-pubdate', 'title']
34  
-        unique_together = ['title', 'author']
  27
+        ordering = ['-pubdate', 'name']
35 28
 
36 29
     def __str__(self):
37  
-        return self.title
  30
+        return self.name
4  tests/signals_regress/tests.py
@@ -77,7 +77,7 @@ def test_model_signals(self):
77 77
             "Is created"
78 78
         ])
79 79
 
80  
-        b1 = Book(title='Snow Crash', pubdate='2012-02-02 12:00')
  80
+        b1 = Book(name='Snow Crash', pubdate='2012-02-02 12:00')
81 81
         self.assertEqual(self.get_signal_output(b1.save), [
82 82
             "pre_save signal, Snow Crash",
83 83
             "post_save signal, Snow Crash",
@@ -87,7 +87,7 @@ def test_model_signals(self):
87 87
     def test_m2m_signals(self):
88 88
         """ Assigning and removing to/from m2m shouldn't generate an m2m signal """
89 89
 
90  
-        b1 = Book(title='Snow Crash', pubdate='2012-02-02 12:00')
  90
+        b1 = Book(name='Snow Crash', pubdate='2012-02-02 12:00')
91 91
         self.get_signal_output(b1.save)
92 92
         a1 = Author(name='Neal Stephenson')
93 93
         self.get_signal_output(a1.save)

0 notes on commit f5d4849

Please sign in to comment.
Something went wrong with that request. Please try again.