Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. from django.db.models import F, Func, Value
  2. from myapp.models import MyModel
  3.  
  4. # Annotation
  5. MyModel.objects.filter(description__icontains='\r\n').annotate(
  6. fixed_description=Func(
  7. F('description'),
  8. Value('\r\n'), Value('\n'),
  9. function='replace',
  10. )
  11. )
  12.  
  13. # Bulk replace/fix
  14. MyModel.objects.filter(description__icontains='\r\n').update(
  15. description=Func(
  16. F('description'),
  17. Value('\r\n'), Value('\n'),
  18. function='replace',
  19. )
  20. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement