I have a syntax error with the following code:
ids_row={}
ids_row["releve_annee"]=int(row[0])
ids_row["releve_mois"]=int(row[1])
ids_row["no_ordre"]=int(row[2])
defaults={}
defaults["titre_rmc"]=row[3].strip()
defaults["notes"]=row[17].strip()
instance, created = Act.objects.get_or_create(**ids_row, defaults=defaults)
My model:
class Act(models.Model):
releve_annee=models.IntegerField(max_length=4, blank=False, null=False)
releve_mois=models.IntegerField(max_length=2, blank=False, null=False)
no_ordre=models.IntegerField(max_length=2, blank=False, null=False)
titre_rmc=models.CharField(max_length=2000, blank=False, null=False)
notes=models.CharField(max_length=2000, blank=True, null=True, default=None)
class Meta:
unique_together=(("releve_annee", "releve_mois", "no_ordre"), )
In a shell:
instance, created = Act.objects.get_or_create(**ids_row, defaults=defaults)
^
SyntaxError: invalid syntax
If I remove defaults=defaults
, the error disappears. What is wrong?
Try changing the sequence of parameters,
instance, created = Act.objects.get_or_create(defaults=defaults, **ids_row)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With