[Answered ]-Replace all spaces to dash in all my "url" object from my article model

1👍

.replace(..) creates a new string, it does not modify the string. You can thus work with:

def index(request):
    change_urls = list(Article.objects.all())
    for i in change_urls:
        i.url = i.url.replace(' ', '-')
    Article.objects.bulk_update(change_urls, fields=('url',))
    # …

But if you want to "slugify", please use the slugify(…) function [Django-doc].

Leave a comment