Ticket #1681: one_to_one.diff
File one_to_one.diff, 5.9 KB (added by , 19 years ago) |
---|
-
django/db/models/fields/related.py
76 76 # but this can be overridden with the "related_name" option. 77 77 return self.rel.related_name or opts.object_name.lower() 78 78 79 def prepare_field_objs_and_params(self, manipulator, name_prefix): 80 params = {'validator_list': self.validator_list[:], 'member_name': name_prefix + self.attname} 81 if self.rel.raw_id_admin: 82 field_objs = self.get_manipulator_field_objs() 83 params['validator_list'].append(curry(manipulator_valid_rel_key, self, manipulator)) 84 else: 85 if self.radio_admin: 86 field_objs = [forms.RadioSelectField] 87 params['ul_class'] = get_ul_class(self.radio_admin) 88 else: 89 if self.null: 90 field_objs = [forms.NullSelectField] 91 else: 92 field_objs = [forms.SelectField] 93 params['choices'] = self.get_choices_default() 94 return field_objs, params 95 79 96 class SingleRelatedObjectDescriptor(object): 80 97 # This class provides the functionality that makes the related-object 81 98 # managers available as attributes on a model class, for fields that have … … 451 468 def get_validator_unique_lookup_type(self): 452 469 return '%s__%s__exact' % (self.name, self.rel.get_related_field().name) 453 470 454 def prepare_field_objs_and_params(self, manipulator, name_prefix):455 params = {'validator_list': self.validator_list[:], 'member_name': name_prefix + self.attname}456 if self.rel.raw_id_admin:457 field_objs = self.get_manipulator_field_objs()458 params['validator_list'].append(curry(manipulator_valid_rel_key, self, manipulator))459 else:460 if self.radio_admin:461 field_objs = [forms.RadioSelectField]462 params['ul_class'] = get_ul_class(self.radio_admin)463 else:464 if self.null:465 field_objs = [forms.NullSelectField]466 else:467 field_objs = [forms.SelectField]468 params['choices'] = self.get_choices_default()469 return field_objs, params470 471 471 def get_manipulator_field_objs(self): 472 472 rel_field = self.rel.get_related_field() 473 473 if self.rel.raw_id_admin and not isinstance(rel_field, AutoField): -
django/contrib/admin/templates/widget/one_to_one.html
1 {% include "widget/foreign.html" %} 1 {% if add %}{% include "widget/foreign.html" %}{% endif %} 2 {% if change %}{% if bound_field.existing_display %} <strong>{{ bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %}{% endif %} -
django/contrib/admin/templates/widget/foreign.html
10 10 {% if bound_field.needs_add_label %} 11 11 <a href="{{ bound_field.related_url }}add/" class="add-another" id="add_{{ bound_field.element_id }}" onclick="return showAddAnotherPopup(this);"> <img src="{% admin_media_prefix %}img/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"/></a> 12 12 {% endif %}{% endif %} 13 {% if change %} 14 {% if bound_field.field.primary_key %} 15 {{ bound_field.original_value }} 16 {% endif %} 17 {% if bound_field.raw_id_admin %} 18 {% if bound_field.existing_display %} <strong>{{ bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %} 19 {% endif %} 20 {% endif %} -
django/contrib/admin/templates/admin/field_line.html
9 9 {% if not bound_field.has_label_first %} 10 10 {% field_label bound_field %} 11 11 {% endif %} 12 {% if change %}13 {% if bound_field.field.primary_key %}14 {{ bound_field.original_value }}15 {% endif %}16 {% if bound_field.raw_id_admin %}17 {% if bound_field.existing_display %} <strong>{{ bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %}18 {% endif %}19 {% endif %}20 12 {% if bound_field.field.help_text %}<p class="help">{{ bound_field.field.help_text }}</p>{% endif %} 21 13 {% endfor %} 22 14 </div> -
docs/model-api.txt
877 877 models can be made by using a string containing the model name. 878 878 879 879 This ``OneToOneField`` will actually replace the primary key ``id`` field 880 (since one-to-one relations share the same primary key), and has a few881 differencesin the admin interface:880 (since one-to-one relations share the same primary key), and will be displayed 881 as a read-only field when you edit an object in the admin interface: 882 882 883 * No ``Place`` selection interface is displayed on ``Restaurant`` pages.884 There will be one (and only one) ``Restaurant`` for each ``Place``.885 886 * On the ``Restaurant`` change list, every ``Place`` -- whether it has an887 associated ``Restaurant`` or not -- will be displayed. Adding a888 ``Restaurant`` to a ``Place`` just means filling out the required889 ``Restaurant`` fields.890 891 883 See the `One-to-one relationship model example`_ for a full example. 892 884 893 885 .. _One-to-one relationship model example: http://www.djangoproject.com/documentation/models/one_to_one/