fromdjango.contrib.admin.utilimportlookup_needs_distinctclassRegexModelAdmin(admin.ModelAdmin):# code coming from django 1.6defget_search_results(self,request,queryset,search_term):""" Returns a tuple containing a queryset to implement the search, and a boolean indicating if the results may contain duplicates. """# Apply keyword searches.defconstruct_search(field_name):iffield_name.startswith('^'):return"%s__istartswith"%field_name[1:]eliffield_name.startswith('='):return"%s__iexact"%field_name[1:]eliffield_name.startswith('@'):return"%s__search"%field_name[1:]eliffield_name.startswith('/')andfield_name.endswith('/')andlen(field_name)>2:return"%s__regex"%field_name[1:-1]else:return"%s__icontains"%field_nameuse_distinct=Falseifself.search_fieldsandsearch_term:orm_lookups=[construct_search(str(search_field))forsearch_fieldinself.search_fields]forbitinsearch_term.split():or_queries=[models.Q(**{orm_lookup:bit})fororm_lookupinorm_lookups]queryset=queryset.filter(reduce(operator.or_,or_queries))ifnotuse_distinct:forsearch_specinorm_lookups:iflookup_needs_distinct(self.opts,search_spec):use_distinct=Truebreakreturnqueryset,use_distinctclassTokenAdmin(RegexModelAdmin):list_display=('token','token_type')search_fields=['/token/','/token_type/',]

Comments

Despite warning coming from django developers, I'm still using admin classes to quickly get into reverse engineering databases.

I think you might find the community divided on this point. The sheer number of admin apps and tweaks shows you're not alone in finding this a good approach to take! Nearly all the major Django CMS projects are heavily based on the Django Admin, for instance.