Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #1017 -- Admin now selects single choice for ForeignKey fields …

…if only one choice is available. Thanks for reporting, Eugene

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1575 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 58220b17d64e761b2d7195417688f90a5724fb44 1 parent dc2daff
@adrianholovaty adrianholovaty authored
Showing with 9 additions and 5 deletions.
  1. +9 −5 django/core/meta/fields.py
View
14 django/core/meta/fields.py
@@ -727,12 +727,16 @@ def get_db_prep_save(self,value):
def flatten_data(self, follow, obj=None):
if not obj:
# In required many-to-one fields with only one available choice,
- # select that one available choice. Note: We have to check that
- # the length of choices is *2*, not 1, because SelectFields always
- # have an initial "blank" value.
- if not self.blank and not self.rel.raw_id_admin and self.choices:
+ # select that one available choice. Note: For SelectFields
+ # (radio_admin=False), we have to check that the length of choices
+ # is *2*, not 1, because SelectFields always have an initial
+ # "blank" value. Otherwise (radio_admin=True), we check that the
+ # length is 1.
+ if not self.blank and (not self.rel.raw_id_admin or self.choices):
choice_list = self.get_choices_default()
- if len(choice_list) == 2:
+ if self.radio_admin and len(choice_list) == 1:
+ return {self.attname: choice_list[0][0]}
+ if not self.radio_admin and len(choice_list) == 2:
return {self.attname: choice_list[1][0]}
return Field.flatten_data(self, follow, obj)
Please sign in to comment.
Something went wrong with that request. Please try again.