Re: Dynamic columns in admin changelists
For me the #django IRC chat logs have given me much success as a reference point as I am a beginner with django. That search on there for me is a goldmine. Steve On 11/21/08, AndyB <[EMAIL PROTECTED]> wrote: > > I basically would like some way for staff users to choose which > columns are displaying in an object's changelist. > > So far I've got an ugly solution which I can actually have some idea > how to implement and the 'correct' solution which requires quite a lot > of digging in the django internals. > > The ugly solution is 'show everything and use jquery to control what > is displayed' > > The correct solution I imagine would involve altering the list_display > properties that are created when the app's admin.py is imported. > > Has anyone tried to do anything like this already? > > Andy > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Dynamic columns in admin changelists
Thanks Malcolm, That was so much easier than I was expecting: class ItemOptions(admin.ModelAdmin): def changelist_view(self, request, extra_context=None): self.list_display = request.session['item_columns'] return super(ItemOptions, self).changelist_view(request, extra_context) Incidentally - while reading around it I found this page which is a treasure trove: http://code.djangoproject.com/wiki/NewformsHOWTO#Q:HowdoIaddanextracolumntothechangelistview If anyone ever want to expands the 'customising the admin' sections of the docs then that's the page to look at. Andy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Dynamic columns in admin changelists
On Fri, 2008-11-21 at 02:08 -0800, AndyB wrote: > I basically would like some way for staff users to choose which > columns are displaying in an object's changelist. > > So far I've got an ugly solution which I can actually have some idea > how to implement and the 'correct' solution which requires quite a lot > of digging in the django internals. > > The ugly solution is 'show everything and use jquery to control what > is displayed' > > The correct solution I imagine would involve altering the list_display > properties that are created when the app's admin.py is imported. > > Has anyone tried to do anything like this already? I haven't tried it, but a couple of minutes looking at the code suggests it shouldn't be too hard. The admin display, by design, is a class-based setup, with particular methods you can override. If you look at the ModelAdmin.changelist_view() method -- which is the one responsible for the page you're interested in -- you'll see that it creates the page using information from attributes on "self". So you could override that method, set up self.list_display and self.list_display_links appropriately and then pass off control to the base class method. That's pretty much the intention of the admin system design: you override the methods you want to change, often just setting up the instance slightly differently before returning to the normal execution paths. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---