Hi Babatunde,

Thanks, I see your point. I know about this solution but thought that
I've missed anything and there is a common approach how to do it
automatically. So, will start working on save() method overriding.

Regards,
Dmitry

On Aug 24, 12:36 pm, Babatunde Akinyanmi <[email protected]> wrote:
> You will need tosavethe A object first. What you can do is override
> thesavemethod for B model. In the function, check for which argument
> in *args is an A object. When found,callthe super method for A's
> defaultsavemethod thencallthe super method for B's defaultsave
> method. That should work just fine.
> I haven't tried it but I believe it would work. I'm an accountant and
> there's a lot of work on my table right now but I could find time
> during break to try algorithm and tell you if it works
>
> On 8/23/11, ernando <[email protected]> wrote:
>
>
>
>
>
>
>
>
>
> > Hi all,
>
> > maybe it's newbie question but I wasn't able to find clear answer/
> > solution on it.
>
> > For example, we have the followingmodels:
>
> > class A(models.Model):
> >     id =models.AutoField(primary_key=True)
> >     title =models.CharField(max_length=30)
>
> > class B(models.Model):
> >     id =models.AutoField(primary_key=True)
> >     title =models.CharField(max_length=30)
> >     aItems =models.OneToOneField(A)
>
> > And try tosavethem in the following way:
>
> > a = A(title="123")
> > b = B(title="333", aItems = a)
> > b.save()
>
> > This code runs with the error: (1364, "Field 'aItems_id' doesn't have
> > a default value")
> > if I firstlysavea object - everything goes smoothly. So, the
> > question is - should we alwayssaveall related objects manually?
> > According to django docs we have to create object at first. But that's
> > now always convenient - e.g. I receive full model from the 3rd part
> > service and want tosaveit into DB withonecalland not do it for
> > each item.
>
> > Regards,
> > Dmitry
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> Sent from my mobile device

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to