from wq.db.patterns import admin
from wq.db.patterns.models import Authority, RelationshipType
from wq.db.patterns.base import swapper
from django.conf import settings


class ResultInline(admin.TabularInline):
    model = swapper.load_model('vera', 'Result')
    extra = 0


class ParameterAdmin(admin.IdentifiedModelAdmin):
    list_display = ('name', 'units')
    list_filter = ('units', 'is_numeric')
    exclude = ('contenttype',)


class ReportAdmin(admin.ModelAdmin):
    inlines = [ResultInline]

# Register models with admin, but only if they haven't been swapped
default_admin = {
    'Site': admin.IdentifiedRelatedModelAdmin,
    'Event': admin.ModelAdmin,
    'Report': ReportAdmin,
    'ReportStatus': admin.ModelAdmin,
    'Parameter': ParameterAdmin,
}
for model in default_admin:
    if swapper.is_swapped('vera', model):
        continue
    admin.site.register(
        swapper.load_model('vera', model),
        default_admin[model]
    )

# Auto-register relevant patterns' type models
admin.site.register(Authority, admin.AuthorityAdmin)
admin.site.register(RelationshipType)

@@ -269,16 +269,122 @@
 a = 0%0A%0A%0A
+class ReportInline(admin.TabularInline):%0A    model = swapper.load_model('vera', 'Report')%0A    extra = 0%0A%0A%0A
 class Pa
@@ -421,24 +421,24 @@
 odelAdmin):%0A
-
     list_dis
@@ -604,16 +604,83 @@
 nline%5D%0A%0A
+%0Aclass EventAdmin(admin.ModelAdmin):%0A    inlines = %5BReportInline%5D%0A%0A
 # Regist
@@ -817,27 +817,21 @@
 Event': 
-admin.Model
+Event
 Admin,%0A 

allow reconfiguration of previously registered models