django - How do I look in a list of items, find the user and see if it exists in a different table and change the template as a result? -
i have simple follow/following setup running.
when user (request.user) see's object likes, can click follow button , follow user.
when returns want button on object not enabled cause following user.
what happening in background, follower/followee record being made. object in question has id of followee. can't figure out how add representation object_list.
in rest add field serializer , take care of it. evaluate truthiness of new field.
any ideas on how accomplish this?
you should separate query , make test in template.
view:
def objects_list(request): ... return render(request, "the_template_path.html", { 'objects': objectname.objects.all()[0:100], 'followed_object_ids': objectname.objects.filter(follower=request.user).values_list('id', flat=true) })
template:
{% object in objects %} {% if object.id in followed_object_ids %} ... {% else %} ... {% endif %} {% endfor %}
that started. don't want use generic names object
.
it better move followed_object_ids query in middleware don't (really useful if have featured objects widgets everywhere instance).
Comments
Post a Comment