I want to perform some delete()
and some save()
methods on some objects that are not an instance of the current class I'm in. I'm trying to do this in an overloaded save()
method of a class. Here is the scenerio:
class Item(models.Model):
name = models.CharField(max_length=500)
category = models.ForeignKey(Category, null=True, related_name='add_item')
tag = models.ManyToManyField(Category, null=True, related_name='tag_item')
def save(self, *args, **kwargs):
super(Item, self).save(*args, **kwargs)
for a_tag in self.tag.all():
#do stuff here
a_tag.delete()
cat = self.category
while cat is not None:
cat.add_item.add(self)
#do stuff here
cat.save()
cat = cat.parent
This doesn't work and when I try to do this I get the following exception:
Exception AttributeError: "'Cursor' object has no attribute 'connection'" in <bound method Cursor.__del__ of <MySQLdb.cursors.Cursor object at 0x905c3ac>> ignored