user 1 have option A and C, user 2 have option A and B
用户1有选项A和C,用户2有选项A和B.
if user A is logued, he can see this
如果用户A被注册,他可以看到这一点
- option A - you have
- option B - you like this? (with a button for add)
- option C - you have
- option D - you like this? (with a button for add)
- option E - you like this? (with a button for add)
选项A - 你有
选项B - 你喜欢这个吗? (带按钮添加)
选项C - 你有
选项D - 你喜欢这个吗? (带按钮添加)
选项E - 你喜欢这个吗? (带按钮添加)
if user 2 is logued, he can see this
如果用户2被注册,他可以看到这一点
- option A - you have
- option B - you have
- option C - you like this? (with a button for add)
- option D - you like this? (with a button for add)
- option E - you like this? (with a button for add)
选项A - 你有
选项B - 你有
选项C - 你喜欢这个吗? (带按钮添加)
选项D - 你喜欢这个吗? (带按钮添加)
选项E - 你喜欢这个吗? (带按钮添加)
but only can do this:
但只能做到这一点:
if user 1 is logued:
如果用户1已注销:
- option A - you have - you like this? (with a button for add)
- option B - you like this? (with a button for add) - you like this? (with a button for add)
- option C - you have - you like this? (with a button for add)
- option D - you like this? (with a button for add) - you like this? (with a button for add)
- option E - you like this? (with a button for add) - you like this? (with a button for add)
选项A - 你有 - 你喜欢这个吗? (带按钮添加)
选项B - 你喜欢这个吗? (带按钮添加) - 你喜欢这个吗? (带按钮添加)
选项C - 你有 - 你喜欢这个吗? (带按钮添加)
选项D - 你喜欢这个吗? (带按钮添加) - 你喜欢这个吗? (带按钮添加)
选项E - 你喜欢这个吗? (带按钮添加) - 你喜欢这个吗? (带按钮添加)
and user 2 :
和用户2:
- option A - you have - you like this? (with a button for add)
- option B - you have - you like this? (with a button for add)
- option C - you like this? (with a button for add) - you like this? (with a button for add)
- option D - you like this? (with a button for add) - you like this? (with a button for add)
- option E - you like this? (with a button for add)
选项A - 你有 - 你喜欢这个吗? (带按钮添加)
选项B - 你有 - 你喜欢这个吗? (带按钮添加)
选项C - 你喜欢这个吗? (带按钮添加) - 你喜欢这个吗? (带按钮添加)
选项D - 你喜欢这个吗? (带按钮添加) - 你喜欢这个吗? (带按钮添加)
选项E - 你喜欢这个吗? (带按钮添加)
my models:
class Options(models.Model):
option_titulo = models.Charfield(max_lenght=100)
user = models.ManyToManyField(User, null=True, blank=True, default=None)
my view:
def ListaOptions(request):
userid=request.user.id
options=Options.objects.all()
opt_user=Options.objects.filter(user__id=userid)
return render_to_response(
'options.html',
{
'options': options,
'opt_user': opt_user,
},
context_instance=RequestContext(request)
)
my template:
{% for o in options %}
{{ o.option_titulo }} -
{% for u in opt_user %}
{% if u.id == o.id %}
you have
{% else %}
you like this? (with a button for add)
{% endif %}
{% endfor %}
{% endfor %}
1 个解决方案
#1
0
You could use in
for each option to test if it's in opt_user
:
您可以使用in为每个选项测试它是否在opt_user中:
{% for o in options %}
{{ o.option_titulo }} -
{% if o in opt_user %}
you have
{% else %}
you like this? (with a button for add)
{% endif %}
{% endfor %}
#1
0
You could use in
for each option to test if it's in opt_user
:
您可以使用in为每个选项测试它是否在opt_user中:
{% for o in options %}
{{ o.option_titulo }} -
{% if o in opt_user %}
you have
{% else %}
you like this? (with a button for add)
{% endif %}
{% endfor %}