Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changelist_view #100

Closed
letspw opened this issue Jan 13, 2014 · 7 comments
Closed

changelist_view #100

letspw opened this issue Jan 13, 2014 · 7 comments

Comments

@letspw
Copy link

letspw commented Jan 13, 2014

Hi,
I user changelist_view method to control which column I want to show in the admin view.
Is there any similar method I can call using xadmin?
Thanks in advance.

@the5fire
Copy link
Contributor

Do you mean list_display in Admin Model?

https://github.com/sshwsfc/django-xadmin/blob/master/demo_app/app/adminx.py#L46

@letspw
Copy link
Author

letspw commented Jan 13, 2014

I mean this https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.changelist_view

My goal is to display different list depending on the logged in user. For instance, if superuser list_display would be ['a', 'b', 'c']
if not list_display ['a','b']

@letspw
Copy link
Author

letspw commented Jan 13, 2014

Can you give me more details or some reference on how to use it?
for instance what do i return?
thanks!

@sshwsfc
Copy link
Owner

sshwsfc commented Jan 13, 2014

return a list include the columns name you want display.

@letspw
Copy link
Author

letspw commented Jan 13, 2014

not sure if this is what you mean

@Property
def list_display(self):
if self.request.user.is_superuser:
list1 = ['a','b','c', 'd', 'e','f',]
return list1

if I do that I keep getting an attribute error at
self.list_display = self.get_list_display()

@sshwsfc
Copy link
Owner

sshwsfc commented Jan 13, 2014

you can override method get_list_display

class MyAdmin(object):
    def get_list_display(self):
        list_display = super(MyAdmin, self). get_list_display()
        user = self.user
        if user.username == 'tom':
            list_display.append('tom_only_field')
        return list_display

@letspw
Copy link
Author

letspw commented Jan 13, 2014

That actually worked out.
Thanks!

@letspw letspw closed this as completed Jan 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants