Reputation: 55
I am trying to delete an element from an arrayfield in notes model
obj=notes.objects.get(id=n_id,related_to__contains=[c_id])
obj.related_to.remove(c_id)
obj.save()
where related to is the arrayfield
related_to=ArrayField(models.IntegerField())
n_id is the note's id and c_id is contact's id. When i try to do this i am getting the error ValueError: list.remove(x): x not in list . I've checked and the c_id is in the arrayfield. What is wrong?
Upvotes: 0
Views: 867
Reputation: 953
Since it finds the object, c_id
is definitely in related_to
field. I believe you are getting this error because c_id
is not an int
type but string
type. You should first convert it to int:
c_id = int(c_id)
obj=notes.objects.get(id=n_id,related_to__contains=[c_id])
....
Upvotes: 1