Django

Code

Changeset 1691

Show
Ignore:
Timestamp:
12/16/05 06:07:27 (3 years ago)
Author:
rjwittams
Message:

Now possible to save in a changeform

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/django/contrib/admin/templates/widget/foreign.html

    r1683 r1691  
    22{% output_all bound_field.form_fields %} 
    33{% 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> 
    55{% else %} 
    66{% 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> 
    88{% endif %}{% endif %} 
  • django/branches/magic-removal/django/contrib/admin/templatetags/admin_modify.py

    r1683 r1691  
    102102 
    103103    def needs_header(self): 
    104         return not isinstance(self.field, meta.AutoField) 
     104        return not isinstance(self.field, models.AutoField) 
    105105 
    106106    def header_class_attribute(self): 
     
    108108 
    109109    def use_raw_id_admin(self): 
    110          return isinstance(self.field.rel, (meta.ManyToOne, meta.ManyToMany)) \ 
     110         return isinstance(self.field.rel, (models.ManyToOne, models.ManyToMany)) \ 
    111111            and self.field.rel.raw_id_admin 
    112112 
  • django/branches/magic-removal/django/contrib/admin/views/main.py

    r1683 r1691  
    4141EMPTY_CHANGELIST_VALUE = '(None)' 
    4242 
     43ADMIN_PREFIX = "/admin/" 
     44 
    4345def _get_mod_opts(app_label, module_name): 
    4446    "Helper function that returns a tuple of (module, opts), raising Http404 if necessary." 
     
    9698             
    9799    raise Http404 # Couldn't find app 
     100 
     101_model_urls = {} 
     102 
     103def 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__ ) 
    98116 
    99117def index(request): 
     
    351369            self.cell_class_attribute = ' class="%s" ' % ' '.join(classes) 
    352370        self._repr_filled = False 
     371 
     372        if field.rel: 
     373            self.related_url = url_for_model(field.rel.to) 
    353374 
    354375    def _fetch_existing_display(self, func_name): 
  • django/branches/magic-removal/django/db/models/fields.py

    r1683 r1691  
    759759        # EXAMPLE: Poll.add_choice() 
    760760        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) 
    762763 
    763764 
  • django/branches/magic-removal/django/db/models/__init__.py

    r1683 r1691  
    814814    def save(self, new_data): 
    815815        add, change, opts, klass = self.add, self.change, self.opts, self.model 
     816        print add, change, opts, klass  
    816817        # TODO: big cleanup when core fields go -> use recursive manipulators. 
    817818        from django.utils.datastructures import DotExpandedDict 
     
    919920     
    920921                    # Create the related item. 
    921                     new_rel_obj = related.opts.get_model_module().Klass(**params) 
     922                    new_rel_obj = related.model(**params) 
    922923     
    923924                    # If all the core fields were provided (non-empty), save the item. 
     
    977978         
    978979class ModelChangeManipulator(AutomaticManipulator): 
    979     change = Fals
    980     add = Tru
     980    change = Tru
     981    add = Fals
    981982     
    982983    def __init__(self, obj_key=None, follow=None):