parent
d2bc9fbce1
commit
d423922729
3 changed files with 29 additions and 0 deletions
@ -0,0 +1,29 @@ |
||||
# -*- coding: utf-8 -*- |
||||
|
||||
from django.core.management.base import BaseCommand |
||||
from accounts.models import User |
||||
|
||||
|
||||
class Command(BaseCommand): |
||||
def handle(self, *args, **options): |
||||
users = User.objects.all().values_list('pk', 'url').order_by('-date_joined') |
||||
self.url_to_pk_dict = dict([(user[1], user[0]) for user in users]) |
||||
self.new_urls = {} |
||||
for pk, url in users: |
||||
self.url_check(pk, url) |
||||
|
||||
def url_check(self, pk, url, new_url=None): |
||||
if not url: |
||||
return |
||||
|
||||
if self.url_to_pk_dict.get((new_url or url), pk) != pk: |
||||
new_url = (new_url or url) + 'u' |
||||
if self.new_urls.get(new_url, pk) != pk: |
||||
new_url = new_url + 'u' |
||||
self.url_check(pk, url, new_url) |
||||
elif new_url is not None: |
||||
self.new_urls[new_url] = pk |
||||
user = User.objects.get(pk=pk) |
||||
user.url = new_url |
||||
user.save() |
||||
print(url, self.url_to_pk_dict.get(url), pk, new_url) |
||||
Loading…
Reference in new issue