Code

Opened 6 years ago

Last modified 4 weeks ago

#9071 assigned New feature

Can't disable "add" popup links in the admin

Reported by: jacob Owned by: burzak
Component: contrib.admin Version: 1.0
Severity: Normal Keywords: pyconuk
Cc: ivan_virabyan, james@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: yes

Description

There's no way to prevent the little green "plus" icons from appearing on related fields in the admin (well, other than removing the related object from the admin). It should be possible to prevent those from appearing -- an admin option would make sense here.

Attachments (6)

add-r9017.diff (2.6 KB) - added by kratorius 6 years ago.
add-r9017-tests.diff (2.0 KB) - added by kratorius 6 years ago.
add-r9050.diff (2.5 KB) - added by kratorius 6 years ago.
add-r9751.diff (5.3 KB) - added by jackymac 5 years ago.
updated patch to so it applies cleanly to SVN-9751, added docs
disable_add_r15922.diff (3.5 KB) - added by burzak 3 years ago.
The last patch is obsolete. Updated the patch and adding test case.
disable_add_r15922_2011-05-05.diff (3.7 KB) - added by burzak 3 years ago.

Download all attachments as: .zip

Change History (29)

comment:1 Changed 6 years ago by kratorius

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to kratorius
  • Patch needs improvement unset

Changed 6 years ago by kratorius

Changed 6 years ago by kratorius

comment:2 Changed 6 years ago by kratorius

  • Has patch set

Attached patch adds an exclude_add option (I'm not happy with the naming, any suggestion is welcome) that allows to specify which related fields shouldn't have the add image. Fields should be specified in a list, like exclude_add = [ 'rel_field1', 'rel_field2' ].

However, docs are missing since I'm not a native english-speaker, so it would be nice if someone else could do that.

comment:3 Changed 6 years ago by adrian

  • Triage Stage changed from Unreviewed to Accepted

I like the idea but haven't tested the patch (note there's a print statement in the patch).

Changed 6 years ago by kratorius

comment:4 Changed 6 years ago by kratorius

  • Needs documentation set

Woops, removed the print statement.

comment:5 follow-up: Changed 6 years ago by mtredinnick

What's the use-case here? If you have permission to add the object, it's giving you a way to add it. If you don't have permission to add objects of that type, it shouldn't be showing the plus-sign, but I believe that's already the case.

Saying that you can add it in one way, but not in another seems inconsistent.

comment:6 in reply to: ↑ 5 Changed 6 years ago by fabionatali

Replying to mtredinnick:

What's the use-case here? If you have permission to add the object, it's giving you a way to add it. If you don't have permission to add objects of that type, it shouldn't be showing the plus-sign, but I believe that's already the case.

Saying that you can add it in one way, but not in another seems inconsistent.

If you have a foreign key with a limit_choices_to filter, then in your admin you get a drop down menu with a selection of items. However, if you add a new item through the green plus link, you can actually circumvent this limit_choices_to filter. You can create a new object which doesn't agree with the limit_choices_to filter and it will be used in the foreign key field despite the filter.

This could be a scenario where disabling the green plus link would make sense.

My 2 cents.

comment:7 Changed 6 years ago by vincent

It seems that if you don't have the permission to add objects of a particular type, the add popup link is still there, and there's an ugly Permission Denied page if you click on it.

I tried with Group or User Permissions, and the problem is still there.

There's an old (3 years old) ticket opened here : http://code.djangoproject.com/ticket/1035

Another patch a little less old here : http://code.djangoproject.com/ticket/2927

But I found no patch for the current version of django.

comment:8 Changed 6 years ago by milan612

Hi,

I tried it with latest version of trunk SVN-9218, but doesnt work for me

Any suggestion ?

Milan

Changed 5 years ago by jackymac

updated patch to so it applies cleanly to SVN-9751, added docs

comment:9 Changed 5 years ago by jackymac

  • Needs documentation unset

I've updated the patch so that it now applies to SVN-9751. Also added some docs. The option is still called "exclude_add." I couldn't think of a better name for it. *shrugs*

I'd be awesome if this could be committed in time for 1.1. Anything I can do to help make that happen?

comment:10 Changed 5 years ago by SmileyChris

  • Owner changed from kratorius to SmileyChris
  • Status changed from new to assigned

Slightly related, I just uploaded a new patch to #1035

comment:11 Changed 5 years ago by SmileyChris

  • Owner changed from SmileyChris to kratorius
  • Status changed from assigned to new

(Sorry, didn't mean to accept the ticket)

comment:12 Changed 5 years ago by floledermann

Btw. you can remove the plus sign by using css - this will not really disable the feature but hide it if you shoot for a more consistent user experience:

#add_id_<<fieldname>> {
    display: none;
}

Best is to look up the id of the element in the admin pages' html source.

If you dont't have an admin css already, you can put this snippet in a file - say css/admin.css - and add a Media class to your Admin class:

    class Media:
        css = {
            'all': [settings.MEDIA_URL + 'css/admin.css']
        }

comment:13 Changed 3 years ago by burzak

  • Owner changed from kratorius to burzak
  • Status changed from new to assigned

I took the idea and I made a new patch. I added a test case that I hope it would be correct and well-done.

Changed 3 years ago by burzak

The last patch is obsolete. Updated the patch and adding test case.

comment:14 Changed 3 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

comment:15 Changed 3 years ago by patchhammer

  • Easy pickings unset
  • Patch needs improvement set

disable_add_r15922.diff fails to apply cleanly on to trunk

Changed 3 years ago by burzak

comment:16 Changed 3 years ago by burzak

  • Patch needs improvement unset

The patch had a little conflic, I updated the patch to apply to trunk.

comment:17 Changed 3 years ago by julien

  • UI/UX set

comment:18 Changed 3 years ago by SmileyChris

Note that it's actually possible to do this now. Since r13708, the related admin widget has a can_add_related attribute.

Using the ModelAdmin.get_form hook, set this to False for the field(s) you want to disable the plus for.

comment:19 Changed 2 years ago by julien

#17547 is a duplicate and has a patch.

comment:20 Changed 2 years ago by atkinsonr@…

At present this isn't possible in an InlineModelAdmin, however the patch in #17547 looks good as it is to BaseModelAdmin.

comment:21 Changed 21 months ago by ivan_virabyan

  • Cc ivan_virabyan added

comment:22 Changed 9 months ago by jaylett

  • Cc james@… added

comment:23 Changed 4 weeks ago by timo

  • Patch needs improvement set

Needs a patch that applies cleanly.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as assigned
The owner will be changed from burzak to anonymous. Next status will be 'assigned'
The ticket will be disowned. Next status will be 'new'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.