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 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 -~----------~----~----~----~------~----~------~--~---