由于这条线,我现在收到以下错误setattr(CsvModel, field.value(), CharField())
错误:“dict”对象不可调用
视图.py
if request.method == 'POST':
form = ConfiguratorForm(data=request.POST)
# Send import to task.
# Clean all data and add to var data.
if form.is_valid():
data = form.cleaned_data
process_upload.delay(upload_id=upload.id, form=data)
任务.py
@task
def process_upload(upload_id, form):
upload = Upload.objects.get(id=upload_id)
upload.process(form=form)
过程
import_this(data=self.filepath, extra_fields=[
{'value': self.group_id, 'position': 5},
{'value': self.uploaded_by.id, 'position': 6}], form=form)
模型.py
def import_this(form, *args, **kw):
# make custom ContactCSVModel
class ContactCSVModel(CsvModel):
for k, v in form:
setattr(CsvModel, v, CharField())
group = DjangoModelField(Group)
contact_owner = DjangoModelField(User)
class Meta:
delimiter = ","
dbModel = Contact
update = {'keys': ["mobile", "group"]}
return ContactCSVModel.import_data(*args, **kw)