我想显示 user.username foreignKey 等于会话用户名的条目列表。我只想显示与会话用户相关的特定数据。
模型.py:
from django.db import models
class User(models.Model):
username = models.CharField(max_length=10)
email = models.EmailField(verbose_name='e-mail')
date_signed = models.DateTimeField('date signed')
class ezMap(models.Model):
map_name = models.CharField(max_length=50, )
user = models.ForeignKey(User)
视图.py:
from django.shortcuts import *
from ezmapping.models import *
def listEzMap(request):
#really not sure how to do it...
username = request.session['username']
user_list = ezMap.objects.get(map_name = username)
return render_to_response("map_list.html", {'user_list': user_list})
map_list.html 模板:
{% extends "base.html" %}
{% block content %}
<div class="list">
<h2> Map list </h2>
{% for object in user_list %}
<li>{{ object.map_name }}</li>
{% endfor %}
</div>
{% endblock %}
感谢您对此的帮助!