mbraak / django-mptt-admin

Django-mptt-admin provides a nice Django Admin interface for Mptt models
https://mbraak.github.io/django-mptt-admin/
Other
294 stars 47 forks source link

Display filtered records in admin #47

Closed neerajsharma7 closed 9 years ago

neerajsharma7 commented 9 years ago

Hi, First of all thanks to you guys. i am using django mptt admin and its working fine for me. but, there is a problem in tree admin view. i want to display selected records in tree view, for this i have override "def queryset(self, request)" in admin view, filtered records are coming is grid view but tree view still displaying all records. please find the code below.

def queryset(self, request): qs = super(EmpAdmin, self).queryset(request) return qs.filter(dept__id=10)

so only those records should be displayed in tree format in which dept_id is 10, but its displaying all records.

mbraak commented 9 years ago

Hello,

I'm afraid you can't filter the queryset for the tree using the get_query method.

Perhaps I could add a filter_tree_queryset that you can optionally override:

class MyAdmin(DjangoMpttAdmin):
  def filter_tree_queryset(self, queryset):
    return queryset.filter(dept__id=10)

Would this be helpful?

Greetings, Marco

neerajsharma7 commented 9 years ago

yeah if this works then please do this. Thanks in advance :)

mbraak commented 9 years ago

I added it to the latest version on github.

neerajsharma7 commented 9 years ago

Thanks, Its working fine for me :)