I have run up against this bug before:
https://code.djangoproject.com/ticket/8892
Recently, it was updated to "duplicate of"
https://code.djangoproject.com/ticket/10811
The TL;DR is
Sometimes when you have models with O2O or FK you can lose data if the
models are saved in the wrong order.
I'm having a similar yet different issue, using Django 1.6.5
I have a Job model with subclasses
class Job(models.Model):
job_number = models.CharField("Job Number", max_length=20,
unique=True, db_index=True)
date_opened = models.DateField()
slug = models.SlugField(max_length=20, unique=True)
def save(self, *args, **kwargs):
if not self.slug:
self.slug = self.job_number
super(Job, self).save(*args, **kwargs)
class WorkshopJob(Job)
job = models.OneToOneField(Job, parent_link=True)
invoice_number = models.CharField("Invoice Number", max_length=30, blank=True)
reported_fault = models.TextField()
And here we see a similar result:
>>> j = WorkshopJob.objects.get(id=9)
>>> j
<WorkshopJob: 1234>
>>> j.date_opened
datetime.date(2014, 6, 26)
>>> j.invoice_number
u'123'
>>> j.findings
u''
>>> j.findings="The CPU doesn't work"
>>> j.findings
"The CPU doesn't work"
>>> j.save()
>>> j.findings
"The CPU doesn't work"
>>> j = WorkshopJob.objects.get(id=10)
>>> j.findings
u''
>>> j = WorkshopJob.objects.get(id=9)
>>> j.findings
u''
>>>
Is this expected behaviour?
Is this caused by having overridden the save method on the Job class
and then not following up with an overridden save method on
WorkshopJob?
As another example:
>>> j = WorkshopCivilJob.objects.get(id=9)
>>> j.findings
u''
>>> j.findings="data"
>>> j.findings
'data'
>>> j.save()
>>> j.findings
'data'
>>> x = WorkshopCivilJob.objects.get(id=9)
>>> x.findings
u''
>>> x == j
True
>>> j == x
True
>>> j.findings
'data'
>>> x.findings
u''
>>>
Now my brain hurts.
How can I fix this?
cheers
L.
--
The idea is that a beautiful image is frameable. Everything you need
to see is there: It's everything you want, and it's very pleasing
because there's no extra information that you don't get to see.
Everything's in a nice package for you. But sublime art is
unframeable: It's an image or idea that implies that there's a bigger
image or idea that you can't see: You're only getting to look at a
fraction of it, and in that way it's both beautiful and scary, because
it's reminding you that there's more that you don't have access to.
It's now sort of left the piece itself and it's become your own
invention, so it's personal as well as being scary as well as being
beautiful, which is what I really like about art like that.
-----------------------------------------------------------------------------------------------------------
Adventure Time http://theholenearthecenteroftheworld.com/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGBeqiNqdYkANeV5PtmgvrYO%3DXL_0KJAAewR%3Des9ytspCecX4w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment