Changeset 3094
- Timestamp:
- 06/06/06 21:46:08 (2 years ago)
- Files:
-
- django/trunk/django/core/management.py (modified) (1 diff)
- django/trunk/docs/model-api.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/management.py
r3083 r3094 837 837 e.add(opts, '"%s": prepopulate_from should be a list or tuple.' % f.name) 838 838 if f.choices: 839 if not type(f.choices) in (tuple, list):840 e.add(opts, '"%s": "choices" should be either a tuple or list.' % f.name)839 if not hasattr(f.choices, '__iter__'): 840 e.add(opts, '"%s": "choices" should be iterable (e.g., a tuple or list).' % f.name) 841 841 else: 842 842 for c in f.choices: django/trunk/docs/model-api.txt
r3059 r3094 446 446 ~~~~~~~~~~~ 447 447 448 A list of 2-tuples to use as choices for this field. 448 An iterable (e.g., a list or tuple) of 2-tuples to use as choices for this 449 field. 449 450 450 451 If this is given, Django's admin will use a select box instead of the … … 481 482 class Foo(models.Model): 482 483 gender = models.CharField(maxlength=1, choices=GENDER_CHOICES) 484 485 Finally, note that choices can be any iterable object -- not necessarily a 486 list or tuple. This lets you construct choices dynamically. But if you find 487 yourself hacking ``choices`` to be dynamic, you're probably better off using 488 a proper database table with a ``ForeignKey``. ``choices`` is meant for static 489 data that doesn't change much, if ever. 483 490 484 491 ``core``
