from django.contrib import admin

from .models import Partner, Stream, Contact, Language


class LanguageAdmin(admin.ModelAdmin):
    search_fields = ('language',)
    list_display = ('language',)

admin.site.register(Language, LanguageAdmin)


class PartnerAdmin(admin.ModelAdmin):
    search_fields = ('company_name',)
    list_display = ('company_name', 'description', 'id', 'get_languages')

admin.site.register(Partner, PartnerAdmin)



class StreamAdmin(admin.ModelAdmin):
    search_fields = ('partner__company_name', 'name',)
    list_display = ('id', 'partner', 'name', 'description', 'get_languages')

admin.site.register(Stream, StreamAdmin)



class ContactAdmin(admin.ModelAdmin):
    search_fields = ('partner__company_name', 'full_name', 'short_name',)
    list_display = ('id', 'title', 'full_name', 'partner', 'email',)

admin.site.register(Contact, ContactAdmin)

@@ -1,12 +1,37 @@
+from django import forms%0A
 from django.
@@ -50,16 +50,66 @@
 rt admin
+%0Afrom TWLight.users.groups import get_coordinators
 %0A%0Afrom .
@@ -313,16 +313,16 @@
 dmin)%0A%0A%0A
-
 class Pa
@@ -343,32 +343,932 @@
 in.ModelAdmin):%0A
+    class CustomModelChoiceField(forms.ModelChoiceField):%0A        %22%22%22%0A        This lets us relabel the users in the dropdown with their recognizable%0A        wikipedia usernames, rather than their cryptic local IDs. It should be%0A        used only for the coordinator field.%0A        %22%22%22%0A        def label_from_instance(self, obj):%0A            return '%7Beditor.wp_username%7D (%7Beditor.home_wiki%7D)'.format(%0A                editor=obj.editor)%0A%0A%0A    def formfield_for_foreignkey(self, db_field, request, **kwargs):%0A        %22%22%22%0A        The coordinator dropdown should limit choices to actual coordinators,%0A        for admin ease of use.%0A        %22%22%22%0A        if db_field.name == %22coordinator%22:%0A            return self.CustomModelChoiceField(%0A                queryset=get_coordinators().user_set.all())%0A        return super(PartnerAdmin, self).formfield_for_foreignkey(%0A            db_field, request, **kwargs)%0A%0A%0A
     search_field

Improve usability of coordinator designation interaction