我有一个django视图,它将shared_user_id提供给django模板:
shared_by = Share.objects.filter(shared_user_id=log_id)
这是我的共享和用户模型:
class Share(models.Model):
users = models.ForeignKey(User)
files = models.ForeignKey(File)
shared_user_id = models.IntegerField()
shared_date = models.TextField()
class User(AbstractBaseUser):
#id = models.IntegerField(primary_key=True)
#identifier = models.CharField(max_length=40, unique=True, db_index=True)
username = models.CharField(max_length=90, unique=True, db_index=True)
create_time = models.DateTimeField(null=True, blank=True)
update_time = models.DateTimeField(null=True, blank=True)
email = models.CharField(max_length=225)
#password = models.CharField(max_length=120)
external = models.IntegerField(null=True, blank=True)
deleted = models.IntegerField(null=True, blank=True)
purged = models.IntegerField(null=True, blank=True)
form_values_id = models.IntegerField(null=True, blank=True)
disk_usage = models.DecimalField(null=True, max_digits=16, decimal_places=0, blank=True)
objects = UserManager()
USERNAME_FIELD = 'email'
class Meta:
db_table = u'galaxy_user'
我在这样的模板中调用:
{% for choice in shared_with_me %}
{% csrf_token %}
<tr class="oddclass">
<td><input type="checkbox" name="choice_shard_with_me" id="choice{{ forloop.counter }}" value="{{ choice.file_name }}" onchange="checkChecked()"/></td>
<td><label for="choice{{ forloop.counter }}">{{ choice.file_name }}</label></td>
<td>{{ choice.type }}</td>
<td>{{ choice.size }}</td>
<td>{{ choice.end_date }}</td>
{% for file in shared_by %}
{% ifequal file.users choice.users %}
{% if forloop %}
<td>{{ file.users.username }}</td>
{% endif %}
{% endifequal %}
{% endfor %}
</tr>
{% endfor %}
以下是模板中每个表的coloumn名称:
文件名,类型,尺寸,共享,共享
在共享中,显示共享该文件的用户的用户名。但是对于同一个用户,用户名重复如下: 与我分享
File Name Type Size Shared On Shared By
ok.txt txt 4.78 MB February 24, 2013, 09:59AM sachitad
ok.txt txt 4.78 MB February 24, 2013, 10:08AM sachitdhiifds sachitdhiifds
NC_008253.fna fna 4.78 MB February 24, 2013, 10:11AMsachitdhiifds sachitdhiifds
NC_008253.fna fna 4.78 MB February 24, 2013, 10:20AM hello
ok.txt txt 4.78 MB February 24, 2013, 10:30AM abcde abcde
我做错了什么?
答案 0 :(得分:0)
您应该检查一组数据。我认为代码:{% for file in shared_by %}
从数据库获取具有特定用户的两个文件记录并打印两次。