liked_or_not = Like.objects.filter (user=request.user).exists. If you want to check if a user liked a specific post, you can dot it like this: liked_or_not = Likes.objects.filter (post_id=post_id, user=request.user).exists () annotate has a different purpose. It annotates each object in the QuerySet with the provided list of query expressions.
Error:TypeError: QuerySet. aggregate() received non- expression(s ): . Solution 2. Solution: Piece.objects.annotate(running_meters = (F(‘piece_length’) * F(‘prime_pieces’)), output_field=FloatField()) Error: TypeError: QuerySet. aggregate() received non- expression(s ): .
6/29/2017 · def validate_values_are_expressions (values, method_name): invalid_args = sorted (str (arg) for arg in values if not hasattr (arg, ‘resolve_expression’)]) if invalid_args: raise TypeError ( ‘Queryset.% s () received non-expression( s ): % s .’ % ( method_name, ‘, ‘. join (invalid_args), ) ), Note. I tried this, which executes without throwing the error: qs = super (EnrollmentManager, self).get_queryset ().annotate ( is_expired= (Value (True, output_field=models.BooleanField ()))) and in the shell I can see it: Enrollment.objects.all () [0].is_expired -> returns True. and I.
A QuerySet is iterable, and it executes its database query the first time you iterate over it. For example, this will print the headline of all entries in the database: for e in Entry.objects.all(): print(e.headline) Note: Dont use this if all you want to do is determine if at least one result exists.
ExpressionWrapper Queryset annotate received non expression ‘ s . How to fix: TypeError: def validate_values_are_expressions (values, method_name): invalid_args = sorted (str (arg) for arg in values if not hasattr (arg, ‘resolve_expression’)]) if invalid_args: raise TypeError ( ‘Queryset.% s () received non-expression( s ): % s .’ % ( method_name, ‘, ‘. join (invalid_args), ) ), ??????????????????????? aggregate ()?annotate ()??????. The second way to generate summary values is to generate an independent summary for each object in a QuerySet. ??????????????? aggregate ()?annotate () ???????. ????????????????????????????. ???????????. from django.db.models import Count.