copy the django/contrib/admin/templates/change_form.html file to your
project/templates/admin/ folder.
The line with {% submit_row %} is what your are searching for: add
whatever you need.
Unisng the context parameter, pass to render_change_form whatever you
want to find in the change_form template. Remember to use mark_safe()
Then in your model admin.py you can do also some dirty (well I advised
you they are dirty) hacks like (in my case they works easily because
I know that my app will run in Italian only:
class ABCAdmin(admin.modelAdmin):
def render_change_form(self, request, context, add=False,
change=False, form_url='', obj=None):
ret = super(ABCAdmin, self).render_change_form(request, context,
add, change, form_url, obj)
# remove "add another"
ret.content = ret.content.replace('<input type="submit" value="Salva
e aggiungi un altro" name="_addanother" />', '')
# remove "add and continue"
ret.content = ret.content.replace('<input type="submit" value="Salva
e continua le modifiche" name="_continue" />', '')
# change the save button text to "send"
ret.content = ret.content.replace('Salva', 'Invia')
# add a link to import data using a csv (the link will point to a
url that is mapped to a custom view)
ret.content = ret.content.replace('Aggiungi messaggio inviato',
'Invia messaggio')
return ret
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>
in admin.py
class RubricaAdmin(admin.ModelAdmin):
list_display = ('cognome', 'nome', 'numero_cellulare',)
list_filter = ('cognome', 'nome', 'numero_cellulare',)
search_fields = ('cognome', 'nome',)
@csrf_protect_m
def changelist_view(self, request, extra_context=None):
import re
ret = super(RubricaAdmin, self).changelist_view(request, extra_context)
ret.content = re.sub('(?<=\d )rubrìca', 'voci', ret.content)
#note it is "importa_csv/" and not "/importa_csv/"
ret.content = ret.content.replace('<a href="add/" class="addlink">',
'<a href="importa_csv/" class="addlink">Importa csv</a></li><li><a
href="add/" class="addlink">')
return ret
def importa_csv(self, request, queryset):
pass
class Media:
css = {'all': ('habble-admin.css',)}
in view.py
# -*- coding: utf-8 -*-
from django.http import HttpResponse
from django.shortcuts import render_to_response
from cruscotto.sms.models import Rubrica
from cruscotto.sms.forms import *
from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe
from django.utils.encoding import force_unicode
from django import template
# Create your views here.
def importa_csv(request):
opts = Rubrica._meta
app_label = opts.app_label
queryset = Rubrica.objects.all()
form = FormCSV_0()
#modifiable_objects = []
#perms_needed = set()
#i = 0
#for obj in queryset:
#if request.user.has_perm('sms.change_rubrica'):
#modifiable_objects.append(obj)
#else:
#perms_needed += 'sms.change_rubrica'
context = {
"title": _("Importa CSV"),
"object_name": force_unicode(opts.verbose_name),
#"deletable_objects": modifiable_objects,
'queryset': queryset,
#"perms_lacking": perms_needed,
'has_change_permission': request.user.has_perm('sms.change_rubrica'),
"opts": opts,
#"root_path": self.admin_site.root_path,
"app_label": app_label,
#'action_checkbox_name': admin.ACTION_CHECKBOX_NAME,
'form': form.as_table(),
'form_url': '{url_scheme}://{h_p}/chpwd/'.format(url_scheme=request.META['wsgi.url_scheme'],
h_p=request.META['HTTP_HOST']),
}
return render_to_response('importa_csv.html', context,
context_instance=template.RequestContext(request))
in urls.py before the admin row:
(r'^admin/sms/rubrica/importa_csv/', 'sms.views.importa_csv'), #
nest inside admin interface! this is important for the ../ links in
the template to work
the template:
{% extends "admin/base_site.html" %}
{% load i18n admin_modify adminmedia %}
{% block extrahead %}{{ block.super }}
<script type="text/javascript" src="../../../jsi18n/"></script>
{{ media }}
{% endblock %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet"
type="text/css" href="{% admin_media_prefix %}css/forms.css" />{%
endblock %}
{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif
%}{% endblock %}
{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }}
change-form{% endblock %}
{% block breadcrumbs %}{% if not is_popup %}
<div class="breadcrumbs">
<a href="../../../">{% trans "Home" %}</a> ›
<a href="../../">{{ app_label|capfirst|escape }}</a> ›
{% if has_change_permission %}<a href="../">{{
opts.verbose_name_plural|capfirst }}</a>{% else %}{{
opts.verbose_name_plural|capfirst }}{% endif %}<!-- ›
{% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{
original|truncatewords:"18" }}{% endif %}-->
</div>
{% endif %}{% endblock %}
{% block content %}
<div id="content-main">
{{ form }}
</div>
{% endblock %}
On Tue, Jun 1, 2010 at 11:07, gderazon <gder...@gmail.com> wrote: