#28512: save() behavior of a parent model class accessed through _ptr attribute
-----------------------------------------+------------------------
Reporter: wckao | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Not sure if this is really a bug, but the behavior is not what I expected.
With model
{{{#!python
from django.db import models
class RelatedModel(models.Model):
name = models.CharField(max_length=20)
class ModelA(models.Model):
related = models.ForeignKey(RelatedModel)
def set_related(self):
self.related = RelatedModel.objects.get(name="related_model2")
self.save()
class ModelB(ModelA):
name = models.CharField(max_length=20)
def set_related(self):
self.modela_ptr.set_related()
}}}
When running the following script
{{{#!python
r1 = RelatedModel.objects.create(name="related_model1")
r2 = RelatedModel.objects.create(name="related_model2")
b1 = ModelB.objects.create(related=r1, name="b1") # b1.related.name ==
"related_model1"
b1.set_related() # b1.related.name should be
"related_model2" now
print(b1.related.name) # shows "related_model1"
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28512>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/048.d7713fdb69f91beae0d146b9846d38af%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.