Hi all,

I'm probably overlooking something very simple, but still cannot explain what the code below does wrong:

With these models:

    class Vorblendplan(models.Model):
        # ...
        pass

    class Mitarbeiter(models.Model):
        # ...
vbp = models.OneToOneField(Vorblendplan, null=True, blank=True, on_delete=models.SET_NULL)

I try to make sure that a Mitarbeiter object has a proper (not None) vbp instance. In the manage.py shell:

>>> ma = Mitarbeiter.objects.get(key="F426")
>>> ma.vbp                                  # ok, initially "None"
>>> ma.vbp = Vorblendplan()
>>> ma.vbp.save()
>>> ma.save()

>>> ma = Mitarbeiter.objects.get(key="F426")
>>> ma.vbp                                  # Why still "None"??

This, in contrast, works:

>>> ma = Mitarbeiter.objects.get(key="F426")
>>> ma.vbp                                  # "None"
>>> v = Vorblendplan()
>>> v.save()
>>> ma.vbp = v
>>> ma.save()

>>> ma = Mitarbeiter.objects.get(key="F426")
>>> ma.vbp                                  # ok, as expected
<Vorblendplan: Vorblendplan object>

Why does the first example not work?

Thank you very much, and best regards,
Carsten

--
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to