1. Brad Montgomery
  2. django-janitor

Commits

Brad Montgomery  committed d7a40b7

added app_label to the ContentType selection

  • Participants
  • Parent commits 489355c
  • Branches default

Comments (0)

Files changed (2)

File janitor/admin.py

View file
  • Ignore whitespace
 from django.contrib import admin
+from forms import FieldSanitizerAdminForm
 from models import FieldSanitizer
 
 class FieldSanitizerAdmin(admin.ModelAdmin):
     list_display = ('content_type', 'field_name', ) 
-
+    form = FieldSanitizerAdminForm
 admin.site.register(FieldSanitizer, FieldSanitizerAdmin)

File janitor/forms.py

View file
  • Ignore whitespace
+from django.contrib.contenttypes.models import ContentType
+from django.forms import ModelChoiceField, ModelForm
+from models import FieldSanitizer
+
+class ContentTypeChoiceFieldWithAppLabel(ModelChoiceField):
+    """
+    A ModelChoiceField for ContentTypes that displays the 
+    app_label in addition to the name. 
+    """
+    def label_from_instance(self, obj):
+        return "%s/%s" % (obj.app_label, obj.name)
+
+class FieldSanitizerAdminForm(ModelForm):
+    content_type = ContentTypeChoiceFieldWithAppLabel(ContentType.objects.all())
+    class Meta:
+        model = FieldSanitizer