'how to scan document using mobile came - django

i'm trying building a scanner from mobile phone camera to upload some documents into my django project , database is postgres

class Document(models.Model):
    booking =models.ForeignKey(Booking,on_delete=models.PROTECT)
    docs = models.ImageField(upload_to=upload_docs)

and this is my views.py

@login_required
def add_new_image(request,id):
    obj = get_object_or_404(Booking,id=id)
    if request.method == 'POST':
        images = request.FILES.getlist('images')
        if images:
            for img in images:
                photo = Document.objects.create(
                    booking=obj,
                    docs = img
                )
                photo.save()
            return redirect(reverse_lazy("booking:add_booking",kwargs={"room_no":obj.room_no.room_no}))
        
    return render(request,'booking/add_img.html',{'obj':obj})

and this is my template

            <form action="" method="POST" enctype="multipart/form-data" dir="ltr">{% csrf_token %}

                <div id="main_form" class="text-lg">
                    <p class="p-2 header rounded-lg text-center text-white">{% trans "adding new documents" %} {{obj.id}}</p>
                    <div class="border border-purple-900 mt-2 rounded-lg p-2 text-center">
                        <p>{% trans "booking number" %}: {{obj.id}}
                        </p>
                    </div>
                                
                </div>
                <hr>

                <div class="form-group m-3">
                    <label>{% trans "choose or scan some documents" %}</label>
                    <input required name="images" type="file" multiple class="form-control-file">
                </div>
                <button class="header pt-2  text-white px-4 p-1 rounded-lg mt-4">{% trans "save" %}</button>
            </form>
            

this only works for uploading existing documents , but i have to let user to upload their documents via their mobile phones .. thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source