Manager for importing StockLocation data

This commit is contained in:
Oliver Walters 2019-09-13 22:44:50 +10:00
parent 37ab3d214d
commit 23b814569a
2 changed files with 38 additions and 5 deletions

View File

@ -52,10 +52,10 @@ class PartCategoryResource(ModelResource):
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)
default_location = Field(attribute='default_location', widget=widgets.ForeignKeyWidget(StockLocation))
class Meta:
model = PartCategory
skip_unchanged = True
@ -70,10 +70,8 @@ class PartCategoryResource(ModelResource):
super().after_import(dataset, result, using_transactions, dry_run, **kwargs)
print("Rebuilding PartCategory tree")
# Rebuild teh PartCategory tree
# Rebuild the PartCategory tree(s)
PartCategory.objects.rebuild()
print("Done!")
class PartCategoryAdmin(ImportExportModelAdmin):

View File

@ -1,11 +1,46 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
from import_export.admin import ImportExportModelAdmin
from import_export.resources import ModelResource
from import_export.fields import Field
import import_export.widgets as widgets
from .models import StockLocation, StockItem
from .models import StockItemTracking
class LocationResource(ModelResource):
""" Class for managing StockLocation data import/export """
parent = Field(attribute='parent', widget=widgets.ForeignKeyWidget(StockLocation))
parent_name = Field(attribute='parent__name', readonly=True)
class Meta:
model = StockLocation
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)
# Rebuild the StockLocation tree(s)
StockLocation.objects.rebuild()
class LocationAdmin(ImportExportModelAdmin):
resource_class = LocationResource
list_display = ('name', 'pathstring', 'description')