Can I use Django F() objects with string concatenation?

前端 未结 3 803
野趣味
野趣味 2020-12-08 04:05

I want to run a django update through the ORM that looks something like this:

MyModel.objects.filter(**kwargs).update(my_field=F(\'my_other_field\')+\'a stri         


        
3条回答
  •  余生分开走
    2020-12-08 04:38

    You can use Concat function https://docs.djangoproject.com/en/1.9/ref/models/database-functions/#concat

    from django.db.models.functions import Concat
    from django.db.models import Value
    
    MyModel.objects.filter(**kwargs).update(my_field=Concat('my_other_field', Value('a string'))
    

提交回复
热议问题