I have 2 models Product and Image:

class Image(models.Model):
    product = models.ForeignKey(Product, related_name='images', on_delete=
models.CASCADE)
    parent = models.ForeignKey('self', blank=True, null=True, 
verbose_name='original 
image', on_delete=models.CASCADE)
    image = models.ImageField(upload_to=file_upload_to)
    image_type = models.CharField(max_length=50)



parent is a Foreign Key to the original image

I use the Image Model in a formset:

ImageFormSet = inlineformset_factory(parent_model=Product, model=Image,
form=ImageModelForm, min_num=1, max_num=4, can_delete=True)



Steps:

    Set the Product Form with the inlineformset for Image
    Show and submit the creation form
    save the original image(s)
    after the original image is saved, create multiple image by cropping 
the original image, using a task
    Edit/Update Form, show as image one of the cropped image (instead of 
original) by modifying(filter by image_type) the Formset queryset

An here appear the issue:

The {{form.id}} value in case of update, is the pk(id) of the cropped 
image, instead of the original image:

<input name="product-image-0-id" value="15" type="hidden">



and when the image is updated, is replacing the cropped image in database 
instead of the original image, and the 'cropped' tasks after and insertion 
in database is wrong.

I tried to replace the value(using a custom widget) instead of the cropped 
image with the pk(id) of the original(parent_id).

but if I do, this, on updating/replacing an older image, the new replacing 
image, is ignored; the form submit with no errors, but the replace image is 
not replaced; the other new images are ok.

So I think is a mechanism that compares the value in the the input with 
what was passed to the form, and if doesn't correspond is jut ignoring.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bb636da0-293e-4427-9da4-966fc652dcc4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to