Django model filter with field_set, keep as queryset -
i have filter list method works, , can used, when try make , order_by on list, in can't done.
how can , keep queryset make order_by after filter applied,
i don't know of there better way work field_set's ?
models:
class case(models.model): user = models.foreignkey(user) .... class share(models.model): case = models.foreignkey(case) .... class field(models.model): case = models.foreignkey(case) field = models.foreignkey(defaultfield) ....
-
object_list = field.objects.all() l = [f f in object_list if f.case.share_set.filter(user=request.user).count()]
this inefficient thing in case. should try , filtering in database as possible. query means db has send field rows django, instantiate them, throw away ones don't match. instead should query ones want:
object_list = field.objects.filter(case__share__user=request.user)
now, being more efficient, have queryset on can call order_by
.
Comments
Post a Comment