Я использую django -tag git и django -import-export. Я хочу добавить теги, используя импорт, но он не работает.
Я думаю, что моя проблема ManyToManyWidget(KnowHow.free_tags)
в этом ряду KnowHowResource, но я не знаю, как решить, и задаюсь вопросом, почему.
Я тоже в этом выпуске . Этот вопрос из этого стекового потока .
free_tags = fields.Field(attribute="free_tags", column_name="free_tags", widget=widgets.ManyToManyWidget(KnowHow.free_tags))
Traceback (most recent call last):
File "repository/sssvenv/lib/python3.6/site-packages/import_export/resources.py", line 528, in import_row
self.save_m2m(instance, row, using_transactions, dry_run)
File "repository/sssvenv/lib/python3.6/site-packages/import_export/resources.py", line 403, in save_m2m
self.import_field(field, obj, data, True)
File "repository/sssvenv/lib/python3.6/site-packages/import_export/resources.py", line 365, in import_field
field.save(obj, data, is_m2m)
File "repository/sssvenv/lib/python3.6/site-packages/import_export/fields.py", line 110, in save
cleaned = self.clean(data)
File "repository/sssvenv/lib/python3.6/site-packages/import_export/fields.py", line 66, in clean
value = self.widget.clean(value, row=data)
File "repository/sssvenv/lib/python3.6/site-packages/import_export/widgets.py", line 414, in clean
return self.model.objects.filter(**{
AttributeError: '_TaggableManager' object has no attribute 'objects'
admin.py
from django.contrib import admin
from import_export import resources
from import_export import fields,widgets
from import_export.admin import ImportExportModelAdmin
from .models import KnowHow
# Register your models here.
class KnowHowResource(resources.ModelResource):
free_tags = fields.Field(attribute="free_tags", column_name="free_tags", widget=widgets.ManyToManyWidget(KnowHow.free_tags))
class Meta:
model = KnowHow
import_id_fields=['id']
#fields =('id', 'author', 'category', 'title', 'text', 'file', 'basic_tag', 'free_tags',)
#admin.site.register(KnowHow)
@admin.register(KnowHow)
class knowHowAdmin(ImportExportModelAdmin):
resource_class = KnowHowResource
models.py
from django.db import models
from django.urls import reverse
from taggit.managers import TaggableManager
class KnowHow(models.Model):
BASIC_TAGS =(
('1','one'),
('2','two'),
('3','three'),
('4','four'),
('5','five'),
('6','six'),
)
CATEGORY =(
('1','Type2'),
('2','Type1'),
)
author = models.ForeignKey('auth.User',on_delete=models.CASCADE)
category = models.CharField(max_length=1,choices=CATEGORY,default='1')
title = models.CharField(max_length=200)
text = models.TextField(blank=True,default=' ')
# delault=' ':import system will give a error if text column is null
file = models.FileField(blank=True,upload_to='explicit_knowhows')
basic_tag = models.CharField(max_length=1,choices=BASIC_TAGS,default='1')
free_tags = TaggableManager(blank=True)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('portal:index')