* needs_better_patch: 0 => 1
* easy: => 0
Comment:
disable_add_r15922.diff fails to apply cleanly on to trunk
--
Ticket URL: <http://code.djangoproject.com/ticket/9071#comment:15>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: 1 => 0
Comment:
The patch had a little conflic, I updated the patch to apply to trunk.
--
Ticket URL: <http://code.djangoproject.com/ticket/9071#comment:16>
* ui_ux: => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/9071#comment:17>
Comment (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.
--
Ticket URL: <https://code.djangoproject.com/ticket/9071#comment:18>
Comment (by julien):
#17547 is a duplicate and has a patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/9071#comment:19>
Comment (by atkinsonr@…):
At present this isn't possible in an InlineModelAdmin, however the patch
in #17547 looks good as it is to BaseModelAdmin.
--
Ticket URL: <https://code.djangoproject.com/ticket/9071#comment:20>
* cc: ivan_virabyan (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/9071#comment:21>
* cc: james@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/9071#comment:22>
* needs_better_patch: 0 => 1
Comment:
Needs a patch that applies cleanly.
--
Ticket URL: <https://code.djangoproject.com/ticket/9071#comment:23>
Comment (by rhunwicks):
For others that end up on this page as the result of a Google Search or
similar, as described on http://stackoverflow.com/questions/10377642/how-
to-use-can-add-related-in-django-admin, the full version of the "Using the
`ModelAdmin.get_form hook`" comment is:
{{{#!python
class ProductAdmin(ModelAdmin):
def get_form(self, request, obj=None, **kwargs):
"""
Don't allow adding new Product Categories
"""
form = super(ProductAdmin, self).get_form(request, obj, **kwargs)
form.base_fields['category'].widget.can_add_related = False
return form
}}}
Given the simplicity of this, do we still need this ticket?
--
Ticket URL: <https://code.djangoproject.com/ticket/9071#comment:24>
* status: assigned => closed
* resolution: => worksforme
Comment:
Closing as per last comment and lack of activity.
--
Ticket URL: <https://code.djangoproject.com/ticket/9071#comment:25>
Comment (by Ryan Castner):
I know this was closed due to inactivity and the ease of doing this, but I
feel like the solution, while working and simple is not obvious and
requires knowledge of the internals of how the admin works to figure out.
A documented setting to attach to model admin like disable_add_related =
('field_name', ...) seems like it would be a better solution.
The purpose of this is for non-technical admins who should have the
ability to add a user but would be confused by the ability to add new
users inline while modifying a page, likely if you are creating a new
model with a foreign key to 'user' for instance, you don't want to be
creating a new user at that time, so displaying the option can only serve
to confuse the user
--
Ticket URL: <https://code.djangoproject.com/ticket/9071#comment:26>
Comment (by Tim Graham):
Not every use case can have a `ModelAdmin` attribute. To keep complexity
under control, I think it's better to avoid adding one where an
alternative exists.
--
Ticket URL: <https://code.djangoproject.com/ticket/9071#comment:27>