Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

magic-removal: Fixed #1681. OneToOneField now works properly in the a…

…dmin system.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2800 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3b0e5d8d2950803c5503dae3af7565987a36f983 1 parent 1a02e9d
@jkocherhans jkocherhans authored
View
8 django/contrib/admin/templates/admin/field_line.html
@@ -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
8 django/contrib/admin/templates/widget/foreign.html
@@ -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
3  django/contrib/admin/templates/widget/one_to_one.html
@@ -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
34 django/db/models/fields/related.py
@@ -76,6 +76,23 @@ def _get_related_query_name(self, opts):
# 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 @@ def get_attname(self):
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
12 docs/model-api.txt
@@ -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.
Please sign in to comment.
Something went wrong with that request. Please try again.