Add () after * must be a sequence, not groups

I am trying to pass the "group" as an extra field using the importer-option from django-adapters , but I get the following error ...

add () the argument after * must be a sequence, not a group

ContactCSVModel.import_data(data=self.filepath, extra_fields="1") 

This is my 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'] } 

model.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') 

Looking at the project on git (see below), there may be problems with the project and many many fields, maybe, if so, how to fix it? or is this my code?

https://github.com/anthony-tresontani/django-adaptors/blob/master/adaptor/model.py#L436

+4
source share
1 answer

Django adapters do not currently support ManyToManyFields. As there are more and more queries about this, I am going to integrate it soon.

If you want a workaround, you should work in 2 steps. The first would be to create a python object using a simple CSVModel, removing:

 dbModel = Contact 

Unfortunately, you will also have to manually update.

Then you will need to explicitly create an instance of django by doing something like:

 contact = Contact.objects.create(first_name = csv_object.first_name, ....) contact.groups.add(csv_object.group) 

Hope that helps

+4
source

Source: https://habr.com/ru/post/1469253/


All Articles