My initial reaction:

The docs, with Tim's correction, will look like:

The ``get_exclude`` method is given the ``HttpRequest`` and the ``obj`` being edited and is expected to return a list of fields, as described above in the :attr:`ModelAdmin.exclude` section.

However, the default implementation of ``get_exclude`` does not return a list at all, it returns None. And, it has to do this, otherwise it would actually break things - currently None is used as a sentinel value and it is different from an empty list (https://github.com/django/django/pull/5214/files#diff-3c42de3e53aba87b32c494f995a728dfL1801)

So, an overridden `get_exclude` method that calls `super` will get surprises, and will have to deal with them.

I would expect a method like `get_exclude` to hide these kind of warts, but for historic reasons it can't. By adding this method, we're adding another wart - a method that is documented as returning a list but doesn't. Of course, we could document all the gory details, but the longer the documentation, the more I think "this just smells". Django has enough warts and smells without adding more.

I realise that `get_fields` already behaves in the same way as the proposed `get_exclude`, but it's not very nice. The behaviour of `get_fieldsets` is much better.

However, having said all this, I realise there is a reasonable use case for this (like Peter Farrell's). Also, the current asymmetry between 'fields' and 'exclude' is also a wart. There must be a lesson for the future in all of this, I'm not sure what exactly...


Luke


On 03/09/15 17:28, Tim Graham wrote:
A pull request has been offered: https://github.com/django/django/pull/5214

It seems simple enough to me. Marc or Luke, would you withdraw your objection after seeing the implementation?

On Wednesday, September 2, 2015 at 7:09:18 AM UTC-4, Ramez Ashraf wrote:

    I agree that there are a lot of of hooks in the admin and we might
    need to better document them or remove unneeded or maybe make a
    revolution :)
    But, with the current api and scheme, having get_exclude is more
    of the expected behavior of Django and i think it should be
    implemented.

    What we should certainly do -i believe- is more documenting the
    admin flow & how it's constructed, best practices to achieve
    certain repeated goals etc..

    Regards,
    Ramez


    On Saturday, June 6, 2015 at 3:43:11 PM UTC+2, Marc Tamlyn wrote:

        I don't think we should add this. Exclude is passed to the
        form, and we already have a way of changing the form based on
        the request. I'd rather see changes made to reduce some of the
        many many ways to select fields in the admin. By my count at
        present we have:

        ModelAdmin.fields
        ModelAdmin.get_fields()
        ModelAdmin.exclude
        ModelAdmin.fieldsets
        ModelAdmin.get_fieldsets()
        ModelAdmin.readonly_fields
        ModelAdmin.get_readonly_fields()
        ModelAdmin.form concrete fields
        ModelAdmin.form.Meta.fields
        ModelAdmin.form.Meta.exclude
        ModelAdmin.get_form()

        There's an argument the only one missing here is
        get_exclude(), but I think the current API is silly.
        Personally, I'd like to see us moving towards us encouraging
        doing more work in the form (and defining the form) rather
        than doing so much in the ModelAdmin class. This may well
        require better support for fieldsets in django.forms.

        Marc

        On 6 June 2015 at 05:06, Peter Farrell
        <[email protected]> wrote:

            We are writing a custom admin for CleanerVersion that
            subclasses ModelAdmin. Just about every attribute has a
            hook method which makes extension easier. For example,
            list_display has get_list_display(). However, exclude
            doesn't have one implemented and it seems like an
            oversight. I'm proposing we add one.

            Our current work seeking is to write a property descriptor
            for exclude but then the admin check fails with it not
            being a tuple or list. Then you have to create a custom
            admin checks class to suppress the exclude check error
            because it's not a tuple or list (but really a descriptor).

            If this is ok, I'Ill write a PR.

            --
            You received this message because you are subscribed to
            the Google Groups "Django developers  (Contributions to
            Django itself)" group.
            To unsubscribe from this group and stop receiving emails
            from it, send an email to [email protected].
            To post to this group, send email to
            [email protected].
            Visit this group at
            http://groups.google.com/group/django-developers
            <http://groups.google.com/group/django-developers>.
            To view this discussion on the web visit
            
https://groups.google.com/d/msgid/django-developers/c1e8762d-1c9f-47e9-8fe7-e9761c27e057%40googlegroups.com
            
<https://groups.google.com/d/msgid/django-developers/c1e8762d-1c9f-47e9-8fe7-e9761c27e057%40googlegroups.com>.
            For more options, visit https://groups.google.com/d/optout
            <https://groups.google.com/d/optout>.


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/ee4e1491-78cb-4e3a-8419-5a054ca079f1%40googlegroups.com <https://groups.google.com/d/msgid/django-developers/ee4e1491-78cb-4e3a-8419-5a054ca079f1%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
Clothes make the man. Naked people have little or no influence on
society.
           -- Mark Twain

Luke Plant || http://lukeplant.me.uk/

--
You received this message because you are subscribed to the Google Groups "Django 
developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/55F45302.8010200%40cantab.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to