Skip to content

Instantly share code, notes, and snippets.

@matthiask
Created March 16, 2013 09:53
Show Gist options
  • Save matthiask/5175744 to your computer and use it in GitHub Desktop.
Save matthiask/5175744 to your computer and use it in GitHub Desktop.
Product admin using specifications
class ProductAdmin(TranslationAdmin):
list_filter = ['is_active', 'categories', 'specification', 'upgrades']
filter_horizontal = ['upgrades', 'categories', 'matching_products']
form = FormWithSpecification
inlines = [
PriceInline,
SpecialPriceInline,
EducationPriceInline,
ProductImageInline,
]
list_display = ('sku', '__unicode__', 'get_price')
prepopulated_fields = {
'slug': ('title',),
}
save_as = True # TODO copy specification fields when saving as new
def get_fieldsets(self, request, obj=None):
fieldsets = super(ProductAdmin, self).get_fieldsets(request, obj=obj)
if obj is not None and obj.specification:
obj.specification.update_fields(obj) # TODO redundant?
# TODO groups!
fieldsets.append((_('Specification'), {
'fields': [field.formfield_name() for field in
obj.fields.select_related('field__group')],
}))
return fieldsets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment