Created
February 1, 2014 15:52
-
-
Save starenka/8754013 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ModuleAdmin(admin.ModelAdmin): | |
class ParentFilter(SimpleListFilter): | |
title = _('Parent') | |
parameter_name = 'parent' | |
def lookups(self, request, model_admin): | |
return [(m.id, m.name) for m in Module.objects.filter(parent__isnull=True).order_by('name')] + [('Null', 'Null')] | |
def queryset(self, request, queryset): | |
if self.value(): | |
if self.value() == 'Null': | |
return queryset.filter(parent__isnull=True) | |
return queryset.filter(parent_id=self.value()) | |
class ModuleForm(forms.ModelForm): | |
parent = forms.ModelChoiceField(queryset=Module.objects.filter(parent__isnull=True).order_by('name'), | |
required=False) | |
list_display = ('name', 'slug', 'parent', 'loan_type', 'type', 'is_active', 'get_app') | |
list_filter = ('type', 'is_active', 'app', ParentFilter) | |
search_fields = ('name', 'slug') | |
prepopulated_fields = {'slug': ('name',)} | |
ordering = ('loan_type', 'parent') | |
form = ModuleForm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment