Fix sortable cols in admin
This commit is contained in:
		
							parent
							
								
									53f28be5ec
								
							
						
					
					
						commit
						c4b8911cc4
					
				
					 3 changed files with 63 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -13,15 +13,20 @@ class RegionAdmin(admin.ModelAdmin):
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
class SiteAdmin(admin.ModelAdmin):
 | 
			
		||||
    list_display = ('name', 'code', 'region', 'description', 'sort_order')
 | 
			
		||||
    list_display = ('name', 'code', 'region_name', 'description', 'sort_order')
 | 
			
		||||
    list_display_links = ('name',)
 | 
			
		||||
    search_fields = ('name', 'code', 'region__name', 'description')
 | 
			
		||||
    list_per_page = 25
 | 
			
		||||
    fields = ('name', 'code', 'region', 'description', 'sort_order')
 | 
			
		||||
 | 
			
		||||
    def region_name(self, obj):
 | 
			
		||||
        return obj.region.name
 | 
			
		||||
    region_name.admin_order_field = 'region__name'
 | 
			
		||||
    region_name.short_description = 'Region'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class MunicipalLocationAdmin(admin.ModelAdmin):
 | 
			
		||||
    list_display = ('name', 'code', 'site', 'municipal_location_type',
 | 
			
		||||
    list_display = ('name', 'code', 'site_name', 'municipal_location_type',
 | 
			
		||||
        'description', 'sort_order')
 | 
			
		||||
    list_display_links = ('name',)
 | 
			
		||||
    search_fields = ('name', 'code', 'site__name', 'municipal_location_type',
 | 
			
		||||
| 
						 | 
				
			
			@ -30,10 +35,15 @@ class MunicipalLocationAdmin(admin.ModelAdmin):
 | 
			
		|||
    fields = ('name', 'code', 'site', 'municipal_location_type',
 | 
			
		||||
        'description', 'sort_order')
 | 
			
		||||
 | 
			
		||||
    def site_name(self, obj):
 | 
			
		||||
        return obj.site.name
 | 
			
		||||
    site_name.admin_order_field = 'site__name'
 | 
			
		||||
    site_name.short_description = 'Site'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StudyLocationAdmin(admin.ModelAdmin):
 | 
			
		||||
    list_display = ('name', 'code', 'site', 'study_location_type',
 | 
			
		||||
        'treatment_type', 'municipal_location', 'collecting_location',
 | 
			
		||||
    list_display = ('name', 'code', 'site_name', 'study_location_type',
 | 
			
		||||
        'treatment_type', 'ml_name', 'collecting_location',
 | 
			
		||||
        'description', 'sort_order')
 | 
			
		||||
    list_display_links = ('name',)
 | 
			
		||||
    search_fields = ('name', 'code', 'site__name', 'study_location_type',
 | 
			
		||||
| 
						 | 
				
			
			@ -44,6 +54,18 @@ class StudyLocationAdmin(admin.ModelAdmin):
 | 
			
		|||
        'treatment_type', 'municipal_location', 'collecting_location',
 | 
			
		||||
        'description', 'sort_order')
 | 
			
		||||
 | 
			
		||||
    def site_name(self, obj):
 | 
			
		||||
        return obj.site.name
 | 
			
		||||
    site_name.admin_order_field = 'site__name'
 | 
			
		||||
    site_name.short_description = 'Site'
 | 
			
		||||
 | 
			
		||||
    def ml_name(self, obj):
 | 
			
		||||
        if obj.municipal_location:
 | 
			
		||||
            return obj.municipal_location.name
 | 
			
		||||
        return obj.municipal_location
 | 
			
		||||
    ml_name.admin_order_field = 'municipal_location__name'
 | 
			
		||||
    ml_name.short_description = 'Municipal Location'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StorageLocationAdmin(admin.ModelAdmin):
 | 
			
		||||
    list_display = ('__str__', 'facility', 'building', 'room', 'freezer', 'temp_c',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,7 @@ class MeasurementUnitAdmin(admin.ModelAdmin):
 | 
			
		|||
 | 
			
		||||
class MeasurementTypeAdmin(admin.ModelAdmin):
 | 
			
		||||
    list_display = ('name', 'code', 'measurement_type_class', 'description',
 | 
			
		||||
        'default_measurement_unit', 'sort_order')
 | 
			
		||||
        'measurement_unit_code', 'sort_order')
 | 
			
		||||
    list_display_links = ('name',)
 | 
			
		||||
    search_fields = ('name', 'code', 'measurement_type_class',
 | 
			
		||||
        'default_measurement_unit__code', 'description')
 | 
			
		||||
| 
						 | 
				
			
			@ -21,10 +21,17 @@ class MeasurementTypeAdmin(admin.ModelAdmin):
 | 
			
		|||
    fields = ('name', 'code', 'measurement_type_class', 'description',
 | 
			
		||||
        'default_measurement_unit', 'sort_order')
 | 
			
		||||
 | 
			
		||||
    def measurement_unit_code(self, obj):
 | 
			
		||||
        if obj.default_measurement_unit:
 | 
			
		||||
            return obj.default_measurement_unit.code
 | 
			
		||||
        return obj.default_measurement_unit
 | 
			
		||||
    measurement_unit_code.admin_order_field = 'default_measurement_unit__code'
 | 
			
		||||
    measurement_unit_code.short_description = 'Default Measurement Unit'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ContainerAdmin(admin.ModelAdmin):
 | 
			
		||||
    list_display = ('name', 'code', 'application', 'color', 'material',
 | 
			
		||||
        'volume', 'measurement_unit', 'sort_order')
 | 
			
		||||
    list_display = ('name', 'code', 'application', 'color_name', 'material_name',
 | 
			
		||||
        'volume', 'measurement_unit_name', 'sort_order')
 | 
			
		||||
    list_display_links = ('name',)
 | 
			
		||||
    search_fields = ('name', 'code', 'application', 'color__name',
 | 
			
		||||
        'material__name', 'volume', 'measurement_unit__name')
 | 
			
		||||
| 
						 | 
				
			
			@ -32,6 +39,27 @@ class ContainerAdmin(admin.ModelAdmin):
 | 
			
		|||
    fields = ('name', 'code', 'application', 'color', 'material',
 | 
			
		||||
        'volume', 'measurement_unit', 'sort_order')
 | 
			
		||||
 | 
			
		||||
    def color_name(self, obj):
 | 
			
		||||
        if obj.color:
 | 
			
		||||
            return obj.color.name
 | 
			
		||||
        return obj.color
 | 
			
		||||
    color_name.admin_order_field = 'color__name'
 | 
			
		||||
    color_name.short_description = 'Color'
 | 
			
		||||
 | 
			
		||||
    def material_name(self, obj):
 | 
			
		||||
        if obj.material:
 | 
			
		||||
            return obj.material.name
 | 
			
		||||
        return obj.material
 | 
			
		||||
    material_name.admin_order_field = 'material__name'
 | 
			
		||||
    material_name.short_description = 'Material'
 | 
			
		||||
 | 
			
		||||
    def measurement_unit_name(self, obj):
 | 
			
		||||
        if obj.measurement_unit:
 | 
			
		||||
            return obj.measurement_unit.name
 | 
			
		||||
        return obj.measurement_unit
 | 
			
		||||
    measurement_unit_name.admin_order_field = 'measurement_unit__name'
 | 
			
		||||
    measurement_unit_name.short_description = 'Measurement Unit'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class MaterialAdmin(admin.ModelAdmin):
 | 
			
		||||
    list_display = ('name', 'code', 'material_class', 'description', 'sort_order')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,7 +27,7 @@ class GrantAdmin(admin.ModelAdmin):
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
class GrantReportAdmin(admin.ModelAdmin):
 | 
			
		||||
    list_display = ('grant', 'title', 'report_type', 'description', 'due_date',
 | 
			
		||||
    list_display = ('grant_title', 'title', 'report_type', 'description', 'due_date',
 | 
			
		||||
        'submitted_date', 'attachment', 'sort_order')
 | 
			
		||||
    list_display_links = ('title',)
 | 
			
		||||
    search_fields = ('grant__title', 'title', 'report_type', 'description', 'due_date',
 | 
			
		||||
| 
						 | 
				
			
			@ -36,6 +36,11 @@ class GrantReportAdmin(admin.ModelAdmin):
 | 
			
		|||
    fields = ('title', 'report_type', 'description', 'due_date',
 | 
			
		||||
        'submitted_date', 'attachment', 'sort_order')
 | 
			
		||||
 | 
			
		||||
    def grant_title(self, obj):
 | 
			
		||||
        return obj.grant.title
 | 
			
		||||
    grant_title.admin_order_field = 'grant__title'
 | 
			
		||||
    grant_title.short_description = 'Grant'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
admin.site.register(Project, ProjectAdmin)
 | 
			
		||||
admin.site.register(Grant, GrantAdmin)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue