1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

magic-removal: Fixed #1681. OneToOneField now works properly in the admin system.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2800 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Joseph Kocherhans 2006-05-01 15:02:39 +00:00
parent 1a02e9d5c3
commit 3b0e5d8d29
5 changed files with 29 additions and 36 deletions

View File

@ -9,14 +9,6 @@
{% if not bound_field.has_label_first %}
{% field_label bound_field %}
{% endif %}
{% if change %}
{% if bound_field.field.primary_key %}
{{ bound_field.original_value }}
{% endif %}
{% if bound_field.raw_id_admin %}
{% if bound_field.existing_display %}&nbsp;<strong>{{ bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %}
{% endif %}
{% endif %}
{% if bound_field.field.help_text %}<p class="help">{{ bound_field.field.help_text }}</p>{% endif %}
{% endfor %}
</div>

View File

@ -10,3 +10,11 @@
{% if bound_field.needs_add_label %}
<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>
{% endif %}{% endif %}
{% if change %}
{% if bound_field.field.primary_key %}
{{ bound_field.original_value }}
{% endif %}
{% if bound_field.raw_id_admin %}
{% if bound_field.existing_display %}&nbsp;<strong>{{ bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %}
{% endif %}
{% endif %}

View File

@ -1 +1,2 @@
{% include "widget/foreign.html" %}
{% if add %}{% include "widget/foreign.html" %}{% endif %}
{% if change %}{% if bound_field.existing_display %}&nbsp;<strong>{{ bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %}{% endif %}

View File

@ -76,6 +76,23 @@ class RelatedField(object):
# but this can be overridden with the "related_name" option.
return self.rel.related_name or opts.object_name.lower()
def prepare_field_objs_and_params(self, manipulator, name_prefix):
params = {'validator_list': self.validator_list[:], 'member_name': name_prefix + self.attname}
if self.rel.raw_id_admin:
field_objs = self.get_manipulator_field_objs()
params['validator_list'].append(curry(manipulator_valid_rel_key, self, manipulator))
else:
if self.radio_admin:
field_objs = [forms.RadioSelectField]
params['ul_class'] = get_ul_class(self.radio_admin)
else:
if self.null:
field_objs = [forms.NullSelectField]
else:
field_objs = [forms.SelectField]
params['choices'] = self.get_choices_default()
return field_objs, params
class SingleRelatedObjectDescriptor(object):
# This class provides the functionality that makes the related-object
# managers available as attributes on a model class, for fields that have
@ -451,23 +468,6 @@ class ForeignKey(RelatedField, Field):
def get_validator_unique_lookup_type(self):
return '%s__%s__exact' % (self.name, self.rel.get_related_field().name)
def prepare_field_objs_and_params(self, manipulator, name_prefix):
params = {'validator_list': self.validator_list[:], 'member_name': name_prefix + self.attname}
if self.rel.raw_id_admin:
field_objs = self.get_manipulator_field_objs()
params['validator_list'].append(curry(manipulator_valid_rel_key, self, manipulator))
else:
if self.radio_admin:
field_objs = [forms.RadioSelectField]
params['ul_class'] = get_ul_class(self.radio_admin)
else:
if self.null:
field_objs = [forms.NullSelectField]
else:
field_objs = [forms.SelectField]
params['choices'] = self.get_choices_default()
return field_objs, params
def get_manipulator_field_objs(self):
rel_field = self.rel.get_related_field()
if self.rel.raw_id_admin and not isinstance(rel_field, AutoField):

View File

@ -877,16 +877,8 @@ string ``"self"`` instead of the model name; references to as-yet undefined
models can be made by using a string containing the model name.
This ``OneToOneField`` will actually replace the primary key ``id`` field
(since one-to-one relations share the same primary key), and has a few
differences in the admin interface:
* No ``Place`` selection interface is displayed on ``Restaurant`` pages.
There will be one (and only one) ``Restaurant`` for each ``Place``.
* On the ``Restaurant`` change list, every ``Place`` -- whether it has an
associated ``Restaurant`` or not -- will be displayed. Adding a
``Restaurant`` to a ``Place`` just means filling out the required
``Restaurant`` fields.
(since one-to-one relations share the same primary key), and will be displayed
as a read-only field when you edit an object in the admin interface:
See the `One-to-one relationship model example`_ for a full example.