Skip to content
Snippets Groups Projects
Commit fce0c3b0 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[common][utils] Move annotation method here

parent feb50ae4
No related branches found
No related tags found
1 merge request!327Refactor update creation api
......@@ -31,6 +31,8 @@ Reusable help functions
from django.core.exceptions import ValidationError
from django.utils.encoding import force_text
from django.utils import six
from django.db.models import CharField, Value as V
from django.db.models.functions import Concat
from docutils import utils
from docutils.nodes import Element
......@@ -145,3 +147,21 @@ def py3_cmp(a, b):
https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
"""
return (a > b) - (a < b)
def annotate_full_name(db_class):
"""
Annotate a query with the asset full name so that it can be more easily
filtered.
"""
return db_class.objects.annotate(
full_name=Concat(
"author__username",
V("/"),
"name",
V("/"),
"version",
output_field=CharField(),
)
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment