Created
January 26, 2017 14:33
-
-
Save craigderington/7a3d6773aeacc4cb7664460010c876ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from django.forms.models import BaseInlineFormSet | |
from .models import Item, ItemLocation | |
@admin.register(Item) | |
class ItemAdmin(admin.ModelAdmin): | |
fieldsets = ( | |
('Item Details', { | |
'fields': ('sku', 'item_name', 'item_description', 'item_search', | |
('item_lead_time', 'item_lead_time_period'), 'reorder_point', 'is_consumable') | |
}), | |
('Category & Group', { | |
'fields': ('item_category', 'item_group', ) | |
}), | |
('Vendor & Manufacturer', { | |
'fields': ('vendor', 'manufacturer') | |
}), | |
('Item Pricing', { | |
'fields': ('unit_price', 'unit_cost') | |
}), | |
) | |
inlines = [ItemLocationInline,] | |
list_display = ('sku', 'item_name', 'vendor', 'total_qty_on_hand', 'total_qty_on_order',) | |
list_display_links = ('sku', 'item_name',) | |
list_filter = ('item_category', 'item_group', 'vendor', 'manufacturer',) | |
search_fields = ['sku', 'item_name', 'item_description', 'item_search', 'vendor'] | |
readonly_fields = ('id',) | |
# override the save_formset method and update the total qty's for each location | |
def save_formset(self, request, form, formset, change): | |
instances = formset.save(commit=False) | |
for instance in instances: | |
instance.save() | |
instance.item.update_totals() | |
formset.save_m2m() | |
class Meta: | |
verbose_name = 'Item' | |
verbose_name_plural = 'Items' | |
ordering = ('-id',) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment