Can I format a string in a Django queryset?

0

I'm trying to simulate this stringformat "% s03d"% (name.upper (), number), in a Django query. It is not as easy as doing the field query in the model because it is not stored in the database.

DummyModel.objects.all().annotate(
    format_str=Concat(Upper(F('name')), F('number'), output_field=CharField())
)

But this is not really what I need, because format_str does not contain the zeros further to the left in F ('number').

    
asked by BigHelmet 20.07.2018 в 09:18
source

0 answers