django-admin2 icon indicating copy to clipboard operation
django-admin2 copied to clipboard

divio: fieldsets should be easy to change

Open digi604 opened this issue 11 years ago • 8 comments

Fieldsets should be easy to add and more important: they should be easy to dynamically change.

digi604 avatar Jun 13 '13 09:06 digi604

@digi604 Can you provide a sample API for changeable fieldsets?

pydanny avatar Jun 13 '13 09:06 pydanny

I don't really know where the right place is... if it should be on the form, on the admin class or even in the template. Let me think about it.

digi604 avatar Jun 13 '13 10:06 digi604

Absolutely a +1 from me on this.

I think it should live on the change-form-view since that's the only place were it will be used. A sample API how to change it would be havin a method that gets the default fieldset object and returns the changed one:

class MyChangeFormView(...):
    def get_fieldset(self, fieldsets):
        # delete a field from the second fieldset
        for i, field in list(enumerate(fieldsets[1]['fields'])):
            if field == 'field_i_want_to_delete':
                del fieldset[1]['fields'][i]
                break
        # add a new field at the end of the first fieldset
        fieldsets[0]['fields'].append('my_extra_field')
        # add a class to the last fieldset
        fieldsets[-1]['classes'].append('wide')
        return fieldsets

The example is using the fieldsets definition that django.contrib.admin is using (read: dicts and lists). We could also introduce a Fieldset object that has somehelper methods, so it makes changing it easier, like:

class MyChangeFormView(...):
    def get_fieldset(self, fieldsets):
        # delete a field from the second fieldset
        fieldsets.remove_field('field_i_want_to_delete')
        # add a new field at the end of the first fieldset
        fieldsets[0].add_field('my_extra_field')
        # add a class to the last fieldset
        fieldsets[-1].add_css_class('wide')
        return fieldsets

gregmuellegger avatar Jun 13 '13 15:06 gregmuellegger

I like your approach, since it removes the scoping issue from the equation. The only downside I can think of is documenting how this is done. :-)

pydanny avatar Jun 14 '13 11:06 pydanny

I started some work here: https://github.com/gregmuellegger/django-admin2/compare/fieldsets I hope to make further progress next week.

gregmuellegger avatar Jul 26 '13 14:07 gregmuellegger

@gregmuellegger ping

auvipy avatar Nov 13 '16 07:11 auvipy

@auvipy Sorry I lost interest in the project a while back, I won't continue work on this in the foreseeable future. Feel free to take the code mentioned in the link above if it is still relevant.

gregmuellegger avatar Nov 14 '16 06:11 gregmuellegger

it's OK. I pulled the code. thanks for your earlier efforts.

auvipy avatar Nov 14 '16 07:11 auvipy