Problem saving photos in a view using django-imagekit -
I am using this code in one of my codes:
Request.method == 'POST': Vehicle = Approval (request.post or none) Photos = Photoformset (request. POST or none) if vehicle. IS_Willid (): Vehicle. (Photo) photo = photoformset (request.post, example = vehicle) Photosyave () Returns HTTPRPSPoint redirect ('/ vehicle /') Other: vehicle = vehicleform (photo) = Photoformset (example = vehicle): vehicle, 'photo': photo }, Context_instance = RequestContext (request))
But I get an error: There is no attribute in 'Vehicle' object 'PK'
when I submit the form Try to do
I have declared PhotosFormSet
like: django.contrib.contenttypes.generic import generic_inlineformset_factory photoformat = generic_inline format from
/ Pre>
returns a new vehicle, but you do not set it in a variable, so it's b How are you able to form the new object format.Then my
photo
class is as follows:class photos (image modell): Name = models.CharField (max_length = 100) original_image = Models.ImageField (upload_to = 'photos') num_views = models.PositiveIntegerField (editable = false, default = 0) status = model Forwardkey (photoposition) content_type = models.ForeignKey (ContentType) object_id = models.PositiveIntegerField () content_object = generic.GenericForeignKey ('content_type', 'object_id') Class IKOptions: spec_module = 'glasses' cache_dir =' photos' image_field = 'original_image Here you have a problem:
vehicle.save () photos = PhotoformSet (Request.post, example = vehicle)
vehicle
here is the form, not the object of the vehicle < Code> .ave ()Instead, just do this:
new_vehicle = vehicle.save () photos = PhotosFormSet (Request. POST, example = new_hehecle)
Comments
Post a Comment