Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango python document object listing even deleted files
    primarykey
    data
    text
    <p>Why this django-python snippet showing deleted files also in uploaded document list ??</p> <p><strong>views.py</strong></p> <pre><code>def lists(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): filename = Document(docfile = request.FILES['docfile']) filename.save() # Redirect to the document list after POST return HttpResponseRedirect(reverse('sdm:lists')) # return render_to_response(reverse('sdm:lists')) else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render_to_response( 'sdm/lists.html', {'documents': documents, 'form': form}, context_instance=RequestContext(request) ) </code></pre> <p><strong>lists.html</strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Minimal Django File Upload Example&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;!-- List of uploaded documents --&gt; {% if documents %} &lt;ul&gt; {% for document in documents %} &lt;li&gt;&lt;a href="{{document.docfile.url }}"&gt;{{ document.docfile.name }}&lt;/a&gt;&lt;/li&gt; {% endfor %} &lt;/ul&gt; {% else %} &lt;p&gt;No documents.&lt;/p&gt; {% endif %} &lt;!-- Upload form. Note enctype attribute! --&gt; &lt;form action="{% url sdm:lists %}" method="post" enctype="multipart/form-data"&gt; {% csrf_token %} &lt;p&gt;{{form.non_field_errors }}&lt;/p&gt; &lt;p&gt;{{form.docfile.label_tag }} {{form.docfile.help_text }}&lt;/p&gt; &lt;p&gt; {{ form.docfile.errors }} {{ form.docfile }} &lt;/p&gt; &lt;p&gt;&lt;input type="submit" name="press" value="Upload" /&gt;&lt;/p&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <p></p> <p><strong>Browser Output</strong> </p> <p><code>f14 is latest uploaded file and rest all files have been deleted from respective folders but why is that it is still showing all files in list when are not even present?</code></p> <p>I am new to django-python but I tried to debug it but found this.</p> <pre><code>&gt;&gt;&gt; from sdm.models import Document &gt;&gt;&gt; Document.objects.all() [&lt;Document: Document object&gt;, &lt;Document: Document object&gt;, &lt;Document: Document object&gt;,&lt;Document: Document object&gt;, &lt;Document: Document object&gt;, &lt;Document: Document object&gt;,&lt;Document: Document object&gt;, &lt;Document: Document object&gt;, &lt;Document: Document object&gt;,&lt;Document: Document object&gt;, &lt;Document: Document object&gt;, &lt;Document: Document object&gt;,&lt;Document: Document object&gt;, &lt;Document: Document object&gt;, &lt;Document: Document object&gt;] </code></pre> <p>Don't know how to see actual objects ??</p> <p><img src="https://i.stack.imgur.com/9stq4.png" alt="enter image description here"></p> <p>Thanks</p> <p><strong>Edit :</strong> As pointed out in answers and comments, I would like to tell you that I am deleting files from the uploaded folder directly. Is there any way that I can force ORM object to update automatically when files are not present in folder</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload