How to upload files in Django and save them (and take other actions in the signal –
post_save) in a different location depending on the format? (jpeg and doc)
def upload(request): user = request.user upload_form = UploadForm(request.POST or None, request.FILES or None) if request.method == "POST": if upload_form.is_valid(): my_model = upload_form.save(commit=False) my_model.user = user my_model.save()
class FileStore(models.Model): user = models.ForeignKey(User) standard = models.FileField(upload_to="standard") after_operation = models.FileField(upload_to="after_ocr",blank=True, null=True)
@receiver(post_save, sender=FileStore) def my_handler(sender,instance, **kwargs): if kwargs['created']: text= image_to_string(Image.open(instance.standard)) ... instance.after_operation = File(text_file) instance.save()
I want if file is
standard field and if file is
.png I need run my signal function.