diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index a295edf..586100b 100644
a
|
b
|
except ImportError:
|
8 | 8 | |
9 | 9 | from django.db import get_creation_module |
10 | 10 | from django.db.models import signals |
| 11 | import django.db.models.query |
11 | 12 | from django.dispatch import dispatcher |
12 | 13 | from django.conf import settings |
13 | 14 | from django.core import validators |
… |
… |
class Field(object):
|
359 | 360 | "Returns a list of tuples used as SelectField choices for this field." |
360 | 361 | first_choice = include_blank and blank_choice or [] |
361 | 362 | if self.choices: |
362 | | return first_choice + list(self.choices) |
| 363 | if callable(self.choices): |
| 364 | choices = list(self.choices()) |
| 365 | elif isinstance(self.choices, django.db.models.query.QuerySet): |
| 366 | choices = [(x._get_pk_val(), smart_unicode(x)) for x in self.choices] |
| 367 | else: |
| 368 | choices = list(self.choices) |
| 369 | return first_choice + choices |
363 | 370 | rel_model = self.rel.to |
364 | 371 | if hasattr(self.rel, 'get_related_field'): |
365 | | lst = [(getattr(x, self.rel.get_related_field().attname), smart_unicode(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)] |
| 372 | lst = [(getattr(x, self.rel.get_related_field().attname), smart_unicode(x)) for x in rel_model._default_manager.all()] |
366 | 373 | else: |
367 | | lst = [(x._get_pk_val(), smart_unicode(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)] |
| 374 | lst = [(x._get_pk_val(), smart_unicode(x)) for x in rel_model._default_manager.all()] |
368 | 375 | return first_choice + lst |
369 | 376 | |
370 | 377 | def get_choices_default(self): |
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 818c8a9..a596bec 100644
a
|
b
|
class ReverseManyRelatedObjectsDescriptor(object):
|
506 | 506 | class ManyToOneRel(object): |
507 | 507 | def __init__(self, to, field_name, num_in_admin=3, min_num_in_admin=None, |
508 | 508 | max_num_in_admin=None, num_extra_on_change=1, edit_inline=False, |
509 | | related_name=None, limit_choices_to=None, lookup_overrides=None, |
| 509 | related_name=None, choices=None, lookup_overrides=None, |
510 | 510 | raw_id_admin=False, parent_link=False): |
511 | 511 | try: |
512 | 512 | to._meta |
… |
… |
class ManyToOneRel(object):
|
516 | 516 | self.num_in_admin, self.edit_inline = num_in_admin, edit_inline |
517 | 517 | self.min_num_in_admin, self.max_num_in_admin = min_num_in_admin, max_num_in_admin |
518 | 518 | self.num_extra_on_change, self.related_name = num_extra_on_change, related_name |
519 | | if limit_choices_to is None: |
520 | | limit_choices_to = {} |
521 | | self.limit_choices_to = limit_choices_to |
| 519 | self.choices = choices |
522 | 520 | self.lookup_overrides = lookup_overrides or {} |
523 | 521 | self.raw_id_admin = raw_id_admin |
524 | 522 | self.multiple = True |
… |
… |
class ManyToOneRel(object):
|
534 | 532 | class OneToOneRel(ManyToOneRel): |
535 | 533 | def __init__(self, to, field_name, num_in_admin=0, min_num_in_admin=None, |
536 | 534 | max_num_in_admin=None, num_extra_on_change=None, edit_inline=False, |
537 | | related_name=None, limit_choices_to=None, lookup_overrides=None, |
| 535 | related_name=None, choices=None, lookup_overrides=None, |
538 | 536 | raw_id_admin=False, parent_link=False): |
539 | 537 | # NOTE: *_num_in_admin and num_extra_on_change are intentionally |
540 | 538 | # ignored here. We accept them as parameters only to match the calling |
541 | 539 | # signature of ManyToOneRel.__init__(). |
542 | 540 | super(OneToOneRel, self).__init__(to, field_name, num_in_admin, |
543 | 541 | edit_inline=edit_inline, related_name=related_name, |
544 | | limit_choices_to=limit_choices_to, |
| 542 | choices=choices, |
545 | 543 | lookup_overrides=lookup_overrides, raw_id_admin=raw_id_admin, |
546 | 544 | parent_link=parent_link) |
547 | 545 | self.multiple = False |
548 | 546 | |
549 | 547 | class ManyToManyRel(object): |
550 | 548 | def __init__(self, to, num_in_admin=0, related_name=None, |
551 | | filter_interface=None, limit_choices_to=None, raw_id_admin=False, symmetrical=True): |
| 549 | filter_interface=None, choices=None, raw_id_admin=False, symmetrical=True): |
552 | 550 | self.to = to |
553 | 551 | self.num_in_admin = num_in_admin |
554 | 552 | self.related_name = related_name |
555 | 553 | self.filter_interface = filter_interface |
556 | | if limit_choices_to is None: |
557 | | limit_choices_to = {} |
558 | | self.limit_choices_to = limit_choices_to |
| 554 | self.choices = choices |
559 | 555 | self.edit_inline = False |
560 | 556 | self.raw_id_admin = raw_id_admin |
561 | 557 | self.symmetrical = symmetrical |
… |
… |
class ForeignKey(RelatedField, Field):
|
586 | 582 | num_extra_on_change=kwargs.pop('num_extra_on_change', 1), |
587 | 583 | edit_inline=kwargs.pop('edit_inline', False), |
588 | 584 | related_name=kwargs.pop('related_name', None), |
589 | | limit_choices_to=kwargs.pop('limit_choices_to', None), |
| 585 | choices=kwargs.pop('choices', None), |
590 | 586 | lookup_overrides=kwargs.pop('lookup_overrides', None), |
591 | 587 | raw_id_admin=kwargs.pop('raw_id_admin', False), |
592 | 588 | parent_link=kwargs.pop('parent_link', False)) |
… |
… |
class ManyToManyField(RelatedField, Field):
|
694 | 690 | num_in_admin=kwargs.pop('num_in_admin', 0), |
695 | 691 | related_name=kwargs.pop('related_name', None), |
696 | 692 | filter_interface=kwargs.pop('filter_interface', None), |
697 | | limit_choices_to=kwargs.pop('limit_choices_to', None), |
| 693 | choices=kwargs.pop('choices', None), |
698 | 694 | raw_id_admin=kwargs.pop('raw_id_admin', False), |
699 | 695 | symmetrical=kwargs.pop('symmetrical', True)) |
700 | 696 | self.db_table = kwargs.pop('db_table', None) |