Problem with creating a one-to-one instance

31 views
Skip to first unread message

Carsten Fuchs

unread,
Apr 19, 2013, 11:43:11 AM4/19/13
to django-d...@googlegroups.com
Dear Django devs,

sorry to bother you here, but I posted to django-users first (https://groups.google.com/d/msg/django-users/WHnCxHkEVjE/9puR4youvwsJ) and there was no reply, so please let me re-try here:

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?

Any hint would very much  be appreciated!  :-)

Thank you very much, and best regards,
Carsten

Jacob Kaplan-Moss

unread,
Apr 19, 2013, 12:18:06 PM4/19/13
to django-developers
Hi Carsten -

On Fri, Apr 19, 2013 at 10:43 AM, Carsten Fuchs <carste...@cafu.de> wrote:
> sorry to bother you here, but I posted to django-users first
> (https://groups.google.com/d/msg/django-users/WHnCxHkEVjE/9puR4youvwsJ) and
> there was no reply, so please let me re-try here:

Unfortunately, we can't help you. Django-developers isn't a "second
level" for django-users; they're completely different lists. The
purpose of this list is to discuss the development of Django itself,
not answer user questions.

You might try waiting a few more days -- you only asked your question
on -users a couple days ago -- and trying again. Or you may want to
try IRC (#django on Freenode) or StackOverflow.

Sorry we can't help,

Jacob

Florian Apolloner

unread,
Apr 19, 2013, 12:22:25 PM4/19/13
to django-d...@googlegroups.com
Hi Carsten,

first of all, django-dev is not a second level support list, so for the future please refrain from posting here just because you get no answer on the user list. As for the issue on hand, try accessing ma.vbp_id after you assign the instance, this should give you some clues.

Cheers,
Florian

P.S.: Also if you want your app to be reusable code in English  and not in German ;)

Carsten Fuchs

unread,
Apr 19, 2013, 12:38:52 PM4/19/13
to django-d...@googlegroups.com
Hi Jacob, hi Florian,

Am 19.04.2013 18:18, schrieb Jacob Kaplan-Moss:
> Unfortunately, we can't help you. Django-developers isn't a "second
> level" for django-users; they're completely different lists. The
> purpose of this list is to discuss the development of Django itself,
> not answer user questions.

I'm very sorry.
Thanks for pointing me to the right places.

Best regards,
Carsten
Reply all
Reply to author
Forward
0 new messages