Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Fix data migration for user display names
Browse files Browse the repository at this point in the history
  • Loading branch information
ptgolden committed Mar 7, 2016
1 parent 449a460 commit f20e7ab
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion editorsnotes/main/migrations/0021_populate_display_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
def populate_usernames(apps, schema_editor):
User = apps.get_model('main', 'User')
for user in User.objects.all():
user.display_name = user._get_display_name()
if user.first_name or user.last_name:
display_name = user.first_name + ' ' + user.last_name
display_name = display_name.strip().rstrip()
else:
display_name = user.username

user.display_name = display_name
user.save()

class Migration(migrations.Migration):
Expand Down

0 comments on commit f20e7ab

Please sign in to comment.