| 314 | # Add a Category object *after* the ModelChoiceField has already been |
| 315 | # instantiated. This proves clean() checks the database during clean() rather |
| 316 | # than caching it at time of instantiation. |
| 317 | >>> Category.objects.create(name='Fourth', url='4th') |
| 318 | <Category: Fourth> |
| 319 | >>> f.clean(4) |
| 320 | <Category: Fourth> |
| 321 | |
| 322 | # Delete a Category object *after* the ModelChoiceField has already been |
| 323 | # instantiated. This proves clean() checks the database during clean() rather |
| 324 | # than caching it at time of instantiation. |
| 325 | >>> Category.objects.get(id=4).delete() |
| 326 | >>> f.clean(4) |
| 327 | Traceback (most recent call last): |
| 328 | ... |
| 329 | ValidationError: [u'Select a valid choice. That choice is not one of the available choices.'] |
| 330 | |