Thanks for the tips, I did know about the get_object_or_404 and had
that there originally but I wanted to rule things out and was hoping
if the pet_id didn't exist, that would throw an error I'm used to
seeing. Unfortunately that seems to not be the problem. I did make the
changes regarding the Media.views field but that didn't seem to make
any difference but does clean the code up a bit. Thanks for your help.
>From the error it looks like a related field doesn't exist but I can't
tell what field it's complaining about. Usually the error messages are
helpful, this time, not so much.
-Chris
On Aug 31, 12:37 pm, TiNo <[EMAIL PROTECTED]> wrote:
> On Fri, Aug 29, 2008 at 6:37 PM, flynnguy <[EMAIL PROTECTED]> wrote:
> > ..
> > However there are certain fields I want to set manually so I tried
> > this:
> > class AddPhotoForm(ModelForm):
> > class Meta:
> > model = Media
> > exclude = ('type', 'pet', 'views')
>
> > def add_pet_photo(request, pet_id):
> > pet = Pet.objects.get(id=pet_id)
>
> It is possible a pet with this id does not exist, so use get_object_or_404,
> or catch the DoesNotExist here and raise a 404.
>
>
>
> > if request.method == 'POST':
> > form = AddPhotoForm(data=request.POST, files=request.FILES)
> > if form.is_valid():
> > added_photo = form.save(commit=False)
> > added_photo.pet = pet
> > added_photo.type = 'P'
> > added_photo.views = 0 # this is a zero and is used as a
> > counter
>
> If you add 'blank=True' to 'views = models.IntegerField(default=0)' in your
> model, you don't need to add the last line. You also don't need the
> 'self.views = 0' in the save method below:
>
>
>
> > def save(self):
> > if not self.id:
> > self.created = datetime.datetime.today()
> > self.views = 0
> > self.updated = datetime.datetime.today()
> > self.thumbnail = create_thumbnail(self.image, THUMB_WIDTH,
> > THUMB_HEIGHT)
> > super(Media, self).save()
>
> Don't think it will solve your problem, some tips though.
>
> TiNo
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---