Changeset 1691
- Timestamp:
- 12/16/05 06:07:27 (3 years ago)
- Files:
-
- django/branches/magic-removal/django/contrib/admin/templates/widget/foreign.html (modified) (1 diff)
- django/branches/magic-removal/django/contrib/admin/templatetags/admin_modify.py (modified) (2 diffs)
- django/branches/magic-removal/django/contrib/admin/views/main.py (modified) (3 diffs)
- django/branches/magic-removal/django/db/models/fields.py (modified) (1 diff)
- django/branches/magic-removal/django/db/models/__init__.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/django/contrib/admin/templates/widget/foreign.html
r1683 r1691 2 2 {% output_all bound_field.form_fields %} 3 3 {% if bound_field.raw_id_admin %} 4 FIXURL<a href="" class="related-lookup" id="lookup_{{ bound_field.element_id }}" onclick="return showRelatedObjectLookupPopup(this);"> <img src="{% admin_media_prefix %}img/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a>4 <a href="{{bound_field.related_url}}" class="related-lookup" id="lookup_{{ bound_field.element_id }}" onclick="return showRelatedObjectLookupPopup(this);"> <img src="{% admin_media_prefix %}img/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a> 5 5 {% else %} 6 6 {% if bound_field.needs_add_label %} 7 FIXURL<a href="/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>7 <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> 8 8 {% endif %}{% endif %} django/branches/magic-removal/django/contrib/admin/templatetags/admin_modify.py
r1683 r1691 102 102 103 103 def needs_header(self): 104 return not isinstance(self.field, m eta.AutoField)104 return not isinstance(self.field, models.AutoField) 105 105 106 106 def header_class_attribute(self): … … 108 108 109 109 def use_raw_id_admin(self): 110 return isinstance(self.field.rel, (m eta.ManyToOne, meta.ManyToMany)) \110 return isinstance(self.field.rel, (models.ManyToOne, models.ManyToMany)) \ 111 111 and self.field.rel.raw_id_admin 112 112 django/branches/magic-removal/django/contrib/admin/views/main.py
r1683 r1691 41 41 EMPTY_CHANGELIST_VALUE = '(None)' 42 42 43 ADMIN_PREFIX = "/admin/" 44 43 45 def _get_mod_opts(app_label, module_name): 44 46 "Helper function that returns a tuple of (module, opts), raising Http404 if necessary." … … 96 98 97 99 raise Http404 # Couldn't find app 100 101 _model_urls = {} 102 103 def url_for_model(model): 104 try: 105 return _model_urls[model] 106 except KeyError: 107 comps = model.__module__.split('.') 108 for mod in models.get_installed_models(): 109 remaining, matched = matches_app(mod, comps) 110 if matched and len(remaining) > 0: 111 comps = comps[: - len(remaining)] + remaining[1:] 112 url = "%s%s/%s/" % (ADMIN_PREFIX, '/'.join(comps) , model.__name__.lower() ) 113 _model_urls[model] = url 114 return url 115 raise ImproperlyConfigured('%s is not a model in an installed app' % model.__name__ ) 98 116 99 117 def index(request): … … 351 369 self.cell_class_attribute = ' class="%s" ' % ' '.join(classes) 352 370 self._repr_filled = False 371 372 if field.rel: 373 self.related_url = url_for_model(field.rel.to) 353 374 354 375 def _fetch_existing_display(self, func_name): django/branches/magic-removal/django/db/models/fields.py
r1683 r1691 759 759 # EXAMPLE: Poll.add_choice() 760 760 if related.opts.app_label == cls._meta.app_label: 761 setattr(cls, 'add_%s' % rel_obj_name, curry(cls._add_related, rel_class=related.model, rel_field=related.field)) 761 func = lambda self, *args, **kwargs: self._add_related(related.model, related.field, *args, **kwargs) 762 setattr(cls, 'add_%s' % rel_obj_name, func) 762 763 763 764 django/branches/magic-removal/django/db/models/__init__.py
r1683 r1691 814 814 def save(self, new_data): 815 815 add, change, opts, klass = self.add, self.change, self.opts, self.model 816 print add, change, opts, klass 816 817 # TODO: big cleanup when core fields go -> use recursive manipulators. 817 818 from django.utils.datastructures import DotExpandedDict … … 919 920 920 921 # Create the related item. 921 new_rel_obj = related. opts.get_model_module().Klass(**params)922 new_rel_obj = related.model(**params) 922 923 923 924 # If all the core fields were provided (non-empty), save the item. … … 977 978 978 979 class ModelChangeManipulator(AutomaticManipulator): 979 change = False980 add = True980 change = True 981 add = False 981 982 982 983 def __init__(self, obj_key=None, follow=None):
