<s> from django . contrib import admin <EOL> from django . contrib . contenttypes . generic import GenericTabularInline <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from . models import Image <EOL> class ImageAdmin ( admin . ModelAdmin ) : <EOL> fields = '<STR_LIT>' . split ( ) <EOL> list_display = '<STR_LIT>' . split ( ) <EOL> class ImageAdminInline ( GenericTabularInline ) : <EOL> model = Image <EOL> ct_field = '<STR_LIT>' <EOL> ct_fk_field = '<STR_LIT>' <EOL> readonly_fields = '<STR_LIT>' , <EOL> allow_add = True <EOL> extra = <NUM_LIT:0> <EOL> admin . site . register ( Image , ImageAdmin ) <EOL> class GalleryAdminMixin : <EOL> def save_formset ( self , request , form , formset , change ) : <EOL> if formset . model == Image : <EOL> instances = formset . save ( commit = False ) <EOL> for instance in instances : <EOL> if not instance . author : <EOL> instance . author = request . user <EOL> instance . save ( ) <EOL> formset . save_m2m ( ) <EOL> return instances <EOL> else : <EOL> return formset . save ( ) <EOL> def images_count ( self , obj ) : <EOL> return obj . images . count ( ) <EOL> images_count . short_description = _ ( '<STR_LIT>' ) </s>
