Beef up admin representation

This commit is contained in:
Matthew Ryan Dillon 2016-01-28 15:15:06 -07:00
parent 3ee15528e8
commit b78d7882d5
7 changed files with 144 additions and 16 deletions

View file

@ -4,8 +4,61 @@ from .models import Region, Site, MunicipalLocation, \
StudyLocation, StorageLocation
admin.site.register(Region)
admin.site.register(Site)
admin.site.register(MunicipalLocation)
admin.site.register(StudyLocation)
admin.site.register(StorageLocation)
class RegionAdmin(admin.ModelAdmin):
list_display = ('name', 'code', 'sort_order')
list_display_links = ('name',)
search_fields = ('name', 'code')
list_per_page = 25
fields = ('name', 'code', 'sort_order')
class SiteAdmin(admin.ModelAdmin):
list_display = ('name', 'code', 'region', 'description', 'sort_order')
list_display_links = ('name',)
search_fields = ('name', 'code', 'region', 'description')
list_per_page = 25
fields = ('name', 'code', 'region', 'description', 'sort_order')
class MunicipalLocationAdmin(admin.ModelAdmin):
list_display = ('name', 'code', 'site', 'municipal_location_type',
'description', 'sort_order')
list_display_links = ('name',)
search_fields = ('name', 'code', 'site', 'municipal_location_type',
'description')
list_per_page = 25
fields = ('name', 'code', 'site', 'municipal_location_type',
'description', 'sort_order')
class StudyLocationAdmin(admin.ModelAdmin):
list_display = ('name', 'code', 'site', 'study_location_type',
'treatment_type', 'municipal_location', 'collecting_location',
'description', 'sort_order')
list_display_links = ('name',)
search_fields = ('name', 'code', 'site', 'study_location_type',
'treatment_type', 'municipal_location', 'collecting_location',
'description')
list_per_page = 25
fields = ('name', 'code', 'site', 'study_location_type',
'treatment_type', 'municipal_location', 'collecting_location',
'description', 'sort_order')
class StorageLocationAdmin(admin.ModelAdmin):
list_display = ('__str__', 'facility', 'building', 'room', 'freezer', 'temp_c',
'description', 'sort_order')
list_display_links = ('__str__',)
search_fields = ('__str__', 'facility', 'building', 'room', 'freezer', 'temp_c',
'description')
list_per_page = 25
fields = ('facility', 'building', 'room', 'freezer', 'temp_c',
'description', 'sort_order')
admin.site.register(Region, RegionAdmin)
admin.site.register(Site, SiteAdmin)
admin.site.register(MunicipalLocation, MunicipalLocationAdmin)
admin.site.register(StudyLocation, StudyLocationAdmin)
admin.site.register(StorageLocation, StorageLocationAdmin)

View file

@ -2,8 +2,54 @@ from django.contrib import admin
from .models import MeasurementUnit, MeasurementType, Container, Material, Color
admin.site.register(MeasurementUnit)
admin.site.register(MeasurementType)
admin.site.register(Container)
admin.site.register(Material)
admin.site.register(Color)
class MeasurementUnitAdmin(admin.ModelAdmin):
list_display = ('name', 'code', 'unit_class', 'description', 'sort_order')
list_display_links = ('name',)
search_fields = ('name', 'code', 'unit_class', 'description')
list_per_page = 25
fields = ('name', 'code', 'unit_class', 'description', 'sort_order')
class MeasurementTypeAdmin(admin.ModelAdmin):
list_display = ('name', 'code', 'measurement_type_class', 'description',
'default_measurement_unit', 'sort_order')
list_display_links = ('name',)
search_fields = ('name', 'code', 'measurement_type_class', 'description')
list_per_page = 25
fields = ('name', 'code', 'measurement_type_class', 'description',
'default_measurement_unit', 'sort_order')
class ContainerAdmin(admin.ModelAdmin):
list_display = ('name', 'code', 'application', 'color', 'material',
'volume', 'measurement_unit', 'sort_order')
list_display_links = ('name',)
search_fields = ('name', 'code', 'application', 'color', 'material',
'volume', 'measurement_unit')
list_per_page = 25
fields = ('name', 'code', 'application', 'color', 'material',
'volume', 'measurement_unit', 'sort_order')
class MaterialAdmin(admin.ModelAdmin):
list_display = ('name', 'code', 'material_class', 'description', 'sort_order')
list_display_links = ('name',)
search_fields = ('name', 'code', 'material_class', 'description')
list_per_page = 25
fields = ('name', 'code', 'material_class', 'description', 'sort_order')
class ColorAdmin(admin.ModelAdmin):
list_display = ('name', 'code', 'color_number', 'sort_order')
list_display_links = ('name',)
search_fields = ('name', 'code', 'color_number')
list_per_page = 25
fields = ('name', 'code', 'color_number', 'sort_order')
admin.site.register(MeasurementUnit, MeasurementUnitAdmin)
admin.site.register(MeasurementType, MeasurementTypeAdmin)
admin.site.register(Container, ContainerAdmin)
admin.site.register(Material, MaterialAdmin)
admin.site.register(Color, ColorAdmin)

View file

@ -12,7 +12,7 @@ class MeasurementUnit(models.Model):
slug = AutoSlugField(populate_from='name')
def __str__(self):
return self.name
return self.code
class Meta:
unique_together = ('name', 'code')

View file

@ -9,8 +9,8 @@ class ProjectGrantInline(admin.TabularInline):
class ProjectAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'code', 'iacuc_number', 'description', 'sort_order')
list_display_links = ('id', 'name')
list_display = ('name', 'code', 'iacuc_number', 'description', 'sort_order')
list_display_links = ('name',)
search_fields = ('name', 'code', 'iacuc_number', 'description')
list_per_page = 25
fields = ('name', 'code', 'iacuc_number', 'description', 'sort_order')
@ -18,6 +18,25 @@ class ProjectAdmin(admin.ModelAdmin):
inlines = [ProjectGrantInline]
class GrantAdmin(admin.ModelAdmin):
list_display = ('title', 'code', 'description', 'sort_order')
list_display_links = ('title',)
search_fields = ('title', 'code', 'description', 'description')
list_per_page = 25
fields = ('title', 'code', 'description', 'projects', 'sort_order')
class GrantReportAdmin(admin.ModelAdmin):
list_display = ('title', 'report_type', 'description', 'due_date',
'submitted_date', 'attachment', 'sort_order')
list_display_links = ('title',)
search_fields = ('title', 'report_type', 'description', 'due_date',
'submitted_date', 'attachment')
list_per_page = 25
fields = ('title', 'report_type', 'description', 'due_date',
'submitted_date', 'attachment', 'sort_order')
admin.site.register(Project, ProjectAdmin)
admin.site.register(Grant)
admin.site.register(GrantReport)
admin.site.register(Grant, GrantAdmin)
admin.site.register(GrantReport, GrantReportAdmin)

View file

@ -28,4 +28,8 @@ class Migration(migrations.Migration):
'ordering': ['sort_order'],
},
),
migrations.AlterUniqueTogether(
name='grantreport',
unique_together=set([('grant', 'title', 'due_date')]),
),
]

View file

@ -50,4 +50,5 @@ class GrantReport(models.Model):
return self.title
class Meta:
unique_together = ('grant', 'title', 'due_date',)
ordering = ['sort_order']

View file

@ -2,6 +2,7 @@ import os
import shutil
from django.core.management.base import BaseCommand
from django.db import IntegrityError
import requests
@ -70,10 +71,14 @@ def _import_data():
FROM tbl_lu_grant_reports;
'''
for r in c.execute(q):
# No PK field in Andre's file
gr = GrantReport(grant_id=r[0], title=r[1], report_type=r[2],
description=r[3], due_date=r[8], submitted_date=r[5],
attachment=r[6], sort_order=r[7])
gr.save()
try:
gr.save()
except IntegrityError:
pass
# Measurement Units
for r in c.execute('SELECT * FROM tbl_lu_measurement_units;'):