Source

mediatr / admin.py

Full commit
from django.contrib import admin

from models import Stream, Item, Filter, Variant, Queue, Meta, Batch
from forms import MultiUploadFormset, UploadForm


class StreamAdmin(admin.ModelAdmin):
    exclude = ['author']
    prepopulated_fields = {"slug": ("name",)}
    list_display = ('__unicode__', 'author')

    def save_model(self, request, obj, form, change):
        obj.author = request.user
        obj.save()

class MetaAdmin(admin.ModelAdmin):
    list_display = ('__unicode__', 'item')

class MetaInline(admin.TabularInline):
    model = Meta
    extra = 0

class VariantAdmin(admin.ModelAdmin):
    list_display = ('__unicode__', 'mime', 'default')
    list_filter = ('default', 'mime')

class ItemAdmin(admin.ModelAdmin):
    exclude = ['user', 'mime', 'batch']
    list_display = ('__unicode__', 'mime', 'upload_date')
    prepopulated_fields = {"slug": ("name",)}
    date_hierarchy = 'upload_date'
    list_filter = ('upload_date', 'mime')
    search_fields = ['name']
    form = UploadForm
    inlines = (MetaInline,)
    
    def save_model(self, request, obj, form, change):
        obj.user = request.user
        obj.save()

class ItemInline(admin.TabularInline):
    model = Item
    fields = ('file', 'name')
    extra = 5

class BatchAdmin(admin.ModelAdmin):
    exclude = ('ident',)
    list_display = ('__unicode__', 'uploaded')
    list_filter = ('uploaded',)
    date_hierarchy = 'uploaded'
    inlines = (ItemInline,)

    def save_formset(self, request, form, formset, change):
        objects = formset.save(commit=False)
        for obj in objects:
            obj.user = request.user
            obj.save()
        formset.save_m2m()
        return objects


admin.site.register(Item, ItemAdmin)
admin.site.register(Batch, BatchAdmin)
admin.site.register(Meta, MetaAdmin)
admin.site.register(Variant, VariantAdmin)
admin.site.register(Stream, StreamAdmin)