Exemple #1
0
                        f, (models.BooleanField, models.NullBooleanField)):
                    list_filter.append(f.name)
                if getattr(f, 'flatchoices', None):
                    list_filter.append(f.name)
                if isinstance(
                    f,
                    (models.CharField,
                     models.SlugField,
                     models.TextField)):
                    search_fields.append(f.name)
            exclude_fields.extend(list_filter)
            options = {
                'list_display': [f.name for f in opts.fields if f.name not in exclude_fields],
                'list_filter': list_filter,
                'list_display_links': [
                    nature_field_name(model)],
                'search_fields': search_fields,
                'list_per_page': 20,
            }
            try:
                admin.site.register(model, **options)
            except BaseException:
                pass

if admin.site.is_registered(User):
    admin.site.unregister(User)

    @admin.register(User)
    class UserAdmin(UserAdmin):
        fieldsets = (
            (None, {'fields': ('username', 'password')}),
Exemple #2
0
 def display_link_field(self):
     return nature_field_name(self.model)
Exemple #3
0
                              models.ForeignKey) and (f.name
                                                      not in exclude_fields):
                    # autocomplete_fields.append(f.name)
                    fk_search_fields = get_fk_search_fileds(f.related_model)
                    if fk_search_fields:
                        fk_fields = map(lambda x: f.name + '__' + x,
                                        fk_search_fields)
                        search_fields.extend(list(fk_fields))
            exclude_fields.extend(list_filter)
            options = {
                # 'autocomplete_fields': autocomplete_fields,
                'list_display':
                [f.name for f in opts.fields if f.name not in exclude_fields],
                'list_filter':
                list_filter,
                'list_display_links': [nature_field_name(model)],
                'search_fields':
                search_fields,
                'list_per_page':
                PER_PAGE,
            }
            try:
                admin.site.register(model, **options)
            except BaseException:
                pass

if admin.site.is_registered(User):
    admin.site.unregister(User)

    @admin.register(User)
    class UserAdmin(UserAdmin):