Ticket #1681: one_to_one.diff

File one_to_one.diff, 5.9 KB (added by jkocherhans, 18 years ago)
  • django/db/models/fields/related.py

     
    7676        # but this can be overridden with the "related_name" option.
    7777        return self.rel.related_name or opts.object_name.lower()
    7878
     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
    7996class SingleRelatedObjectDescriptor(object):
    8097    # This class provides the functionality that makes the related-object
    8198    # managers available as attributes on a model class, for fields that have
     
    451468    def get_validator_unique_lookup_type(self):
    452469        return '%s__%s__exact' % (self.name, self.rel.get_related_field().name)
    453470
    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, params
    470 
    471471    def get_manipulator_field_objs(self):
    472472        rel_field = self.rel.get_related_field()
    473473        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 %}&nbsp;<strong>{{ bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %}{% endif %}
  • django/contrib/admin/templates/widget/foreign.html

     
    1010{% if bound_field.needs_add_label %}
    1111    <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>
    1212{% 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 %}&nbsp;<strong>{{ bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %}
     19    {% endif %}
     20{% endif %}
  • django/contrib/admin/templates/admin/field_line.html

     
    99  {% if not bound_field.has_label_first %}
    1010    {% field_label bound_field %}
    1111  {% 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 %}&nbsp;<strong>{{ bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %}
    18     {% endif %}
    19   {% endif %}
    2012  {% if bound_field.field.help_text %}<p class="help">{{ bound_field.field.help_text }}</p>{% endif %}
    2113{% endfor %}
    2214</div>
  • docs/model-api.txt

     
    877877models can be made by using a string containing the model name.
    878878
    879879This ``OneToOneField`` will actually replace the primary key ``id`` field
    880 (since one-to-one relations share the same primary key), and has a few
    881 differences in the admin interface:
     880(since one-to-one relations share the same primary key), and will be displayed
     881as a read-only field when you edit an object in the admin interface:
    882882
    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 an
    887       associated ``Restaurant`` or not -- will be displayed. Adding a
    888       ``Restaurant`` to a ``Place`` just means filling out the required
    889       ``Restaurant`` fields.
    890 
    891883See the `One-to-one relationship model example`_ for a full example.
    892884
    893885.. _One-to-one relationship model example: http://www.djangoproject.com/documentation/models/one_to_one/
Back to Top