我正在尝试使用django-adaptors 的importer-option将“组”作为额外字段传递,但出现以下错误...
* 后的 add() 参数必须是序列,而不是 Group
ContactCSVModel.import_data(data=self.filepath, extra_fields="1")
这是我的 CsvModel...
CSVModel.py
class ContactCSVModel(CsvModel):
first_name = CharField()
last_name = CharField()
company = CharField()
mobile = CharField()
groups = DjangoModelField(Group)
class Meta:
delimiter = "^"
dbModel = Contact
update = {
'keys': ['mobile']
}
模型.py
class Contact(models.Model):
"""
Stores all contacts.
"""
first_name = models.CharField(max_length=60)
last_name = models.CharField(max_length=60)
company = models.CharField(max_length=100,blank=True)
mobile = models.IntegerField(max_length=20)
active = models.BooleanField(help_text="States if pet type is active/selectable.")
modified = models.DateTimeField(null=True, auto_now=True, help_text="Shows when object was modified.")
created = models.DateTimeField(auto_now_add=True, help_text="Shows when object was created.")
#FK
groups = models.ManyToManyField(Group, related_name='contacts')
查看 git 上的项目(如下),项目和 many2many 字段是否有任何问题,如果是,如何解决?还是我的代码?
https://github.com/anthony-tresontani/django-adaptors/blob/master/adaptor/model.py#L436