Actually, from the db-api documentation. "To create an object, instantiate it using keyword arguments to the model class, then call save() to save it to the database. ...
... Django doesn't hit the database until you explicitly call save()." The code: obj = Product(name='Apple') obj.id will not be set until you either explicitly set it, or call save(), at which time django will utilize the lack of a pk (among other things) to determine whether or not to do an insert or update. -richard On Sep 23, 2007, at 9:38 AM, Alex Koshelev wrote: > > I think that when you create Product object django inserts new row > into database and retrieves with SELECT new id. > > On 23 сент, 16:00, Siah <[EMAIL PROTECTED]> wrote: >> Hi, >> >> When in a model you run something like this: >> >>>> obj = Product(name='Apple') >>>> obj.id >> >> 4 >> >> I realize the first statement will turn into an insert table. But, >> how >> does django know of its newly assigned primary key(ID). >> >> I have a legacy database whose ID is assigned with an after trigger, >> and am trying to understand how I can integrate them. >> >> Thanks, >> Sia > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---