Ok, some experimentation has yielded that the problem lies here:
def photoDir(self, filename):
        "Callable method used to set directory of media below"
        return os.path.join('pet_photos', str(self.pet.id), filename)
Basically what seems to be happening is that it tries to save the file
and then continue on to the post save(commit=False) bits.
Unfortunately in my case, when saving the file, it looks at the pet.id
so I can save the image in say /media/pet_photos/1/ so I have all the
photos related to a pet in the same directory but I haven't set it
yet.

Anyone have any suggestions on a way around this? I was thinking of
having a hidden field but still changing it post save(commit=False) to
avoid a user changing it but that just seems unelegant and I also
can't see a way to set the default value for the hidden field. (adding
defalt=whatever on the forms.CharField() doesn't seem to work)
-Chris

On Sep 2, 12:35 pm, flynnguy <[EMAIL PROTECTED]> wrote:
> I tried the id thing which didn't seem to work but then when I tried
> the null thing I think I found out what is going on. It looks like the
> callable save bit for the photo is not getting a pet id so it doesn't
> know where to save it. Of course this is just a guess and I have no
> proof... some more fiddling is needed.
> -Chris
>
> On Sep 2, 12:21 pm, Daniel Roseman <[EMAIL PROTECTED]>
> wrote:
>
> > On Sep 2, 4:04 pm, flynnguy <[EMAIL PROTECTED]> wrote:
>
> > > Found out what was causing the error but not why...
>
> > > It seems that when I tell my model to not exclude the "pet" field,
> > > that everything works fine. (ie, I select a pet from the dropdown)
> > > When I add it to the exclude list and try to set it manually I get an
> > > error.
>
> > > What seems to work is allowing the pet selection but then setting it
> > > after I do save(commit=False). I'm trying to set it up as a hidden
> > > field but I keep getting that it's a required field. I can't seem to
> > > figure out how to set a default value. Any ideas why this might be
> > > happening?
> > > -Chris
>
> > You could try this;
> >  added_photo.pet_id = pet.id
>
> > That might work. Otherwise, try allowing null=True in the pet FK
> > field, and doing form.save() then adding the pet then saving again.
> > --
> > DR
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to