Skip to content

Commit

Permalink
fix: migrations created_by (#1712)
Browse files Browse the repository at this point in the history
* fix: migrations created_by

* added list comprehension

* huddle
  • Loading branch information
KamilPawel committed Oct 10, 2022
1 parent 37c26ba commit d45ba57
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions aimmo/migrations/0030_update_created_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
def populate_created_by(apps, schema_editor):
Game = apps.get_model("aimmo", "Game")
db_alias = schema_editor.connection.alias
games = Game.objects.using(db_alias).all()
for game in games:
if not game.created_by:
game.created_by = game.owner
games = Game.objects.using(db_alias).filter(created_by=None).exclude(owner=None)
[Game.objects.using(db_alias).filter(id=game.id).update(created_by=game.owner.new_teacher) for game in games]


class Migration(migrations.Migration):
Expand Down

0 comments on commit d45ba57

Please sign in to comment.