Change "Add another" text in inline views

121 views
Skip to first unread message

stu...@longlandclan.yi.org

unread,
Aug 30, 2014, 8:05:19 PM8/30/14
to django...@googlegroups.com
Hi all,

This is a bit of a silly question, but I wonder if it is possible to change the "Add Another" text that appears on inline forms with related models.  I'm in the process of writing a network configuration module in Django that talks with NetworkManager with the intent on using it for headless appliances for energy management and possibly SCADA applications.

I have a number of polymorphic models (thank-you django-polymorphic!) that describe the various types of network connection, and attached to these, are some "settings" objects that describe different aspects of the connection.  Some of these are one-to-many relationships (e.g. IP addresses, routes, DNS servers), but some are one-to-one relationships (IPv4/IPv6 options: which specify things like DHCP vs static, 802.1x settings, bridge port configuration, etc).

The form at present looks like this: http://www.longlandclan.yi.org/~stuartl/images_tmp/django-inlines-add-another.png

Also of note is the capitalisation of some objects, e.g. "Ipv4" instead of "IPv4", but I guess I just missed a Meta variable somewhere.  I think I have seen something that sets this.

For the related objects that are one-to-one, I've defined my admin models like so:

class IPv4SettingAdmin(admin.StackedInline):
    model
= models.NetIPv4Setting
    extra
= 0
    min_num
= 0
    max_num
= 1

i.e. the related object is optional, not provided by default, and at most there can only be one.  You'll note that despite max_num being set to 1, it still says "Add another".  Is it possible to delete the word "another" from that text to make it more sensible?  (Better yet, can it drop the word "another" when the count currently sits at 0 since "another" implies an object of that type already exists?)

Apologies if this has been asked: I've only seen replies to the question of how to remove the "add another" option completely, which isn't what I want to do.

Regards,
Stuart Longland

Mike Dewhirst

unread,
Aug 31, 2014, 1:46:54 AM8/31/14
to django...@googlegroups.com
> to 1, it still says "Add//another". Is it possible to delete the word
> "another" from that text to make it more sensible? (Better yet, can it
> drop the word "another" when the count currently sits at 0 since
> "another" implies an object of that type already exists?)

I'm somewhat interested in your success with this because I enjoy it
when the user interface helps the user understand the software. But I
think you might have to dig a little deeper for a nice solution.

I found where the Admin has "add another" ...

Searching for: add another
options.py(945): msg = _('The %(name)s "%(obj)s" was added successfully.
You may add another %(name)s below.') % msg_dict
options.py(983): msg = _('The %(name)s "%(obj)s" was changed
successfully. You may add another %(name)s below.') % msg_dict
widgets.py(262): % (static('admin/img/icon_addlink.gif'), _('Add Another')))
Found 3 occurrence(s) in 2 file(s)

... which all looks interesting but maybe too big a job for the
anticipated benefit.

Good luck

Mike


>
> Apologies if this has been asked: I've only seen replies to the question
> of how to remove the "add another" option completely, which isn't what I
> want to do.
>
> Regards,
> Stuart Longland
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9489756e-4813-43cf-8aa8-6cbfedbd87af%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/9489756e-4813-43cf-8aa8-6cbfedbd87af%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Stuart Longland

unread,
Aug 31, 2014, 1:55:08 AM8/31/14
to django...@googlegroups.com
Hi Mike,
On 31/08/14 15:46, Mike Dewhirst wrote:
>> i.e. the related object is optional, not provided by default, and at
>> most there can only be one. You'll note that despite max_num being set
>> to 1, it still says "Add//another". Is it possible to delete the word
>> "another" from that text to make it more sensible? (Better yet, can it
>> drop the word "another" when the count currently sits at 0 since
>> "another" implies an object of that type already exists?)
>
> I'm somewhat interested in your success with this because I enjoy it
> when the user interface helps the user understand the software. But I
> think you might have to dig a little deeper for a nice solution.
>
> I found where the Admin has "add another" ...
>
> Searching for: add another
> options.py(945): msg = _('The %(name)s "%(obj)s" was added successfully.
> You may add another %(name)s below.') % msg_dict
> options.py(983): msg = _('The %(name)s "%(obj)s" was changed
> successfully. You may add another %(name)s below.') % msg_dict
> widgets.py(262): % (static('admin/img/icon_addlink.gif'), _('Add
> Another')))
> Found 3 occurrence(s) in 2 file(s)
>
> ... which all looks interesting but maybe too big a job for the
> anticipated benefit.

I'll admit I didn't think to just do a grep of the file structure. When
I do it I get:

> /usr/lib/python2.7/dist-packages/django/contrib/admin/locale/en/LC_MESSAGES/django.po:msgid "Add another %(verbose_name)s"
> /usr/lib/python2.7/dist-packages/django/contrib/admin/templates/admin/edit_inline/tabular.html: addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|capfirst as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}",
> /usr/lib/python2.7/dist-packages/django/contrib/admin/templates/admin/edit_inline/stacked.html: addText: "{% blocktrans with verbose_name=inline_admin_formset.opts.verbose_name|capfirst %}Add another {{ verbose_name }}{% endblocktrans %}"

The latter two being the HTML templates used for the stacked and tabular
inline widgets. I guess that's a starting point then. :-)

Regards,
--
Stuart Longland (aka Redhatter, VK4MSL)

I haven't lost my mind...
...it's backed up on a tape somewhere.
Reply all
Reply to author
Forward
0 new messages