Is it possible to use f-strings with Concat(), Value() and F()
I have a varchar column whose values I would like to update. Here is what I have tried so far:
for item in Item.objects.filter():
some_items = get_some_items(item)
Item.objects.filter(field=item.field).difference(some_items).update(
field=Concat(
Value(settings.PREFIX), Value(f"{F('id'):>010d}")
)
)
Which gives me TypeError: unsupported format string passed to F.__format__
I need help on how I can achieve this if possible.
Considering the fact that my use case of the f-string was padding, the LPAD and CAST database functions came in handy (I definitely need to study SQL). Here is the update query:
Item.objects.update(
field=Concat(
Value('prefix'), LPad(Cast('id', output_field=CharField()), 11, Value('0'))
)
)