mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Management class for PartCategory import / export
This commit is contained in:
parent
89acc778f5
commit
bacd70687d
@ -41,8 +41,38 @@ class PartAdmin(ImportExportModelAdmin):
|
|||||||
list_display = ('full_name', 'description', 'total_stock', 'category')
|
list_display = ('full_name', 'description', 'total_stock', 'category')
|
||||||
|
|
||||||
|
|
||||||
|
class PartCategoryResource(ModelResource):
|
||||||
|
""" Class for managing PartCategory data import/export """
|
||||||
|
|
||||||
|
parent = Field(attribute='parent', widget=widgets.ForeignKeyWidget(PartCategory))
|
||||||
|
|
||||||
|
default_location = Field(attribute='default_location', widget=widgets.ForeignKeyWidget(StockLocation))
|
||||||
|
|
||||||
|
parent_name = Field(attribute='parent__name', readonly=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PartCategory
|
||||||
|
skip_unchanged = True
|
||||||
|
report_skipped = False
|
||||||
|
|
||||||
|
exclude = [
|
||||||
|
# Exclude MPTT internal model fields
|
||||||
|
'lft', 'rght', 'tree_id', 'level',
|
||||||
|
]
|
||||||
|
|
||||||
|
def after_import(self, dataset, result, using_transactions, dry_run, **kwargs):
|
||||||
|
|
||||||
|
super().after_import(dataset, result, using_transactions, dry_run, **kwargs)
|
||||||
|
|
||||||
|
print("Rebuilding PartCategory tree")
|
||||||
|
# Rebuild teh PartCategory tree
|
||||||
|
PartCategory.objects.rebuild()
|
||||||
|
print("Done!")
|
||||||
|
|
||||||
class PartCategoryAdmin(ImportExportModelAdmin):
|
class PartCategoryAdmin(ImportExportModelAdmin):
|
||||||
|
|
||||||
|
resource_class = PartCategoryResource
|
||||||
|
|
||||||
list_display = ('name', 'pathstring', 'description')
|
list_display = ('name', 'pathstring', 'description')
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user