Opened 8 years ago
Last modified 18 months ago
#26706 closed Bug
ManyToMany clear doesn't clear the items from the object but deletes from db — at Initial Version
Reported by: | Sharat M R | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | manytomany m2m clear |
Cc: | mattdentremont@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
class Media(models.Model): name = models.CharField(max_length=100) class Tag(models.Model): tag = models.CharField(max_length=100) medias = models.ManyToManyField(Media) def __unicode__(self): return self.tag
Assume tag object below already has three items of Media model in medias which are saved in db. [m1, m2, m3].
tag = Tag.objects.get(id=1) tag.medias.clear() print(tag.medias.all())
The above code prints all the three [m1, m2, m3]. Fetching the tag again using get and printing givens an empty list "[ ]"
Note:
See TracTickets
for help on using tickets.