B
B
bubo2015-12-21 13:55:58
Django
bubo, 2015-12-21 13:55:58

Django MPTT and Django-import-export. Error importing categories. How to decide?

Hello. I'm having this problem
I'm trying to import categories (which were created with Django MPTT) using Django-import-export but I'm getting this error

ValueError: Cannot assign "'Досуг'": "Category.parent" must be a "Category" instance.

models.py
class Category(MPTTModel):
    name = models.CharField(max_length=50, unique=True)
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)

    class MPTTMeta:
        order_insertion_by = ['name']

admin.py
class CategoryResource(resources.ModelResource):

    class Meta:
        model = Category
        exclude = ('lft', 'rght', 'tree_id', 'level')

class CategoryMPTTModelAdmin(ImportExportMixin, MPTTModelAdmin):
    mptt_level_indent = 20
    resource_class = CategoryResource

How can this problem be solved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
belanchuk, 2015-12-21
@belanchuk

ValueError: Cannot assign "'Досуг'": "Category.parent" must be a "Category" instance.

You are trying to assign the string "Leisure" to the parent category, and you need an instance of 'Category.
First, get an instance of a Category called Leisure.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question