Re: Get pk before commit

2010-07-09 Thread Andy McKay
> I'd like to save the image file into a folder based on the ID of the > new instance. I wouldn't actually recommend saving your file with the filename being the primary key of your model anyway. It makes it a pain if you do database dumps or loads and need to keep the primary key in sync with y

Re: Get pk before commit

2010-07-09 Thread TheIvIaxx
that only seems to work on ModelForm, not Model. Or did i miss something? That functionality seems to be what i'm after though :) On Jul 8, 4:07 pm, Kenneth Gonsalves wrote: > On Friday 09 July 2010 03:16:28 TheIvIaxx wrote: > > > I'd like to save the image file into a folder based on the ID of

Re: Get pk before commit

2010-07-08 Thread Kenneth Gonsalves
On Friday 09 July 2010 03:16:28 TheIvIaxx wrote: > I'd like to save the image file into a folder based on the ID of the > new instance. The only thing i can think of is to create the new > folder mid transaction. I guess another way to do it would be to save > a new instance with a temp file or s

Re: Get pk before commit

2010-07-08 Thread TheIvIaxx
Lets say for a model i have the following: class Image(models.Model): image = models.ImageField() >>> image = Image() >>> # Somehow get ID >>> destination = open('ID/name.jpg', 'wb+') >>> for chunk in f.chunks(): ...destination.write(chunk) >>> destination.close() >>> image.image = "I

Re: Get pk before commit

2010-05-29 Thread Praveen
Did you really mean for commit=FALSE or pre_save signal??? Praveen On May 29, 5:22 pm, Euan Goddard wrote: > Hi, > > Could you explain the situation in a little more detail as I don't > quite follow what you mean. As far as I'm aware if you have something > like the following: > > >>> my_inst = M

Re: Get pk before commit

2010-05-29 Thread Euan Goddard
Hi, Could you explain the situation in a little more detail as I don't quite follow what you mean. As far as I'm aware if you have something like the following: >>> my_inst = MyModel(foo="bar", ...) >>> my_inst.save() You'll have the pk at this point even if the transaction hasn't been committed

Get pk before commit

2010-05-28 Thread TheIvIaxx
Hello, I am trying to figure out how to get a pk in the middle of a transaction. I need to set a field in the model based on the ID(default pk) to be given. As far as a i know, this ID should be allocated during the transaction. So i would imagine it would do the INSERT, then i could get the pk a