How to import django-taggit tag in django-import-export

杀马特。学长 韩版系。学妹 提交于 2020-01-25 07:20:26

问题


I can't import Django-taggit tags using Django-import-export.

This error is when the value is entered.

Line number: 1 - invalid literal for int() with base 10: 'def'

Also, this error is when the value is blank.

Line number: 2 - Cannot add <QuerySet []> (<class 'django.db.models.query.QuerySet'>). Expected <class 'django.db.models.base.ModelBase'> or str.

I also posted question in This issue.

xlsx table there is an id column too.

models.py

from django.db import models
from django.urls import reverse
from taggit.managers import TaggableManager

class KnowHow(models.Model):    

    author = models.ForeignKey('auth.User',on_delete=models.CASCADE)
    title = models.CharField(max_length=200)
    text = models.TextField(blank=True)
    file = models.FileField(blank=True,upload_to='explicit_knowhows')
    free_tags = TaggableManager(blank=True)

    def __str__(self):
        return self.title

admin.py

from django.contrib import admin
from import_export import resources
from import_export import fields
from import_export.admin import ImportExportModelAdmin

from .models import KnowHow
# Register your models here.

class KnowHowResource(resources.ModelResource):

    class Meta:
        model = KnowHow
        import_id_fields = ['id']

@admin.register(KnowHow)
class knowHowAdmin(ImportExportModelAdmin):
    resource_class = KnowHowResource

来源:https://stackoverflow.com/questions/59582619/how-to-import-django-taggit-tag-in-django-import-export

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!