You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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).
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:
classIPv4SettingAdmin(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 "Addanother". 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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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 do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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.