I have this unique field on my Profile model:
email = models.EmailField(max_length=200, unique=True)
and I have this ProfileResource:
class ProfileResource(resources.ModelResource):
# associated_issuer = fields.Field(attribute='add_associated_issuer', widget=ManyToManyWidget(Issuer, field='name'), column_name='Associated Issuer')
email = fields.Field(attribute='email',
widget=CharWidget(),
column_name='email')
class Meta:
model = Profile
clean_model_instances = True
import_id_fields = ('id', 'email')
def before_import_row(self, row, row_number=None, **kwargs):
try:
self.email = row["email"]
except Exception as e:
self.email = ""
try:
if row["id"] == '':
row["id"] = None
self.id = row["id"]
except Exception as e:
self.id = None
try:
self.firstname = row["firstname"]
except Exception as e:
self.firstname = ""
try:
self.lastname = row["lastname"]
except Exception as e:
self.lastname = ""
Now when I try to do an import from a file, I receive this error:
I need to be able to do an update_or_create method, but where do I add that code? I tried doing it on an after_import_instance but it did not work.
I also tried on import_row like this:
def import_row(self, row, instance_loader, using_transactions=True, dry_run=False, **kwargs):
try:
Profile.objects.update_or_create(email=self.email)
except Exception as e:
print(e, file=sys.stderr)
but it produced this error:
Exception Value: 'NoneType' object has no attribute 'import_type'
Any insights on a fix would be appreciated.
