How to retrieve a data requested by user from django models?
<p>I have a <em>model</em> and it has  <strong>user</strong> table as  "foreign key" in it . I need a query by which i can get user requested value . </p>

<p>Here is  my models:
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>from django.db import models
#from django.contrib.auth.models import User
 
from django.db import models
from datetime import datetime    
 
from django.conf import settings

class schedulesdb(models.Model):
    f_name = models.CharField(max_length=100)
    dateAndTime = models.DateTimeField(['%Y-%m-%d %H:%M:%S'],null=True)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1)

    def __unicode__(self):              #  on Python 2
        return self.f_name
 </code></pre>
</div>
</div>
</p>

<p>I was trying in this way I don't know what was wrong here :</p>

<p>Here is my views.py:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>def dashboard(request):
container=[]
DIR = os.path.realpath("/home/user/Desktop/Demo")
WAY = os.listdir(DIR)
for file in WAY:
    if file.endswith('.mp4'):
        file_name = file
        FDIR=os.path.join(DIR, file)
        container.append(FDIR)
        
return render(request, 'dashboard.html', {'container': container})

def new_scheduler(request):
if request.method =='POST':
    f_name = request.POST.get('file')
    dateAndTime = request.POST.get('dateAndTime')
Scheduled_data = schedulesdb.objects.create(
        f_name = file,
        dateAndTime = dateAndTime,  
    )
Scheduled_data.save()
return HttpResponse ('done')


def new_job(request):
user = request.user
print user.username
print user.id
   
schedule_entries = schedulesdb.objects.filter(user=request.user)
print schedule_entries.dateAndTime


return HttpResponse(schedule_entries)</code></pre>
</div>
</div>
</p>

<p>Here is my Traceback:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>Performing system checks...

System check identified no issues (0 silenced).
October 17, 2016 - 16:10:43
Django version 1.8, using settings 'pro1.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
goku
2
[]
[17/Oct/2016 16:10:51]"GET /job/ HTTP/1.1" 200 0</code></pre>
</div>
</div>
</p>

<p>Thanks in advance #peace</p>

<p>In order to select all the records from <code>schedulesdb</code> model that relate to the current user, do the following.</p>

<pre><code>def new_job(request):    
    schedule_entries = schedulesdb.objects.filter(user=request.user)
    return HttpResponse(schedule_entries)
</code></pre>

<p>P.S. It is always better to follow the Python convention, so that other programmers can read your code faster. Start by reading the <a href="https://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP-8 Style Guide</a></p>

python sql django