Last active
May 27, 2020 16:03
-
-
Save reg3x/e1efe559b2b46d3fa404a67a61ba57ad to your computer and use it in GitHub Desktop.
[create worlds] method to create worls #skylab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handle(self, *args, **options): | |
company = Company.objects.filter(title="Skylabapps").first() | |
if company: | |
Planet.objects.get_or_create(company=company) | |
Planet.objects.filter(company=company).update(company_name="Skylabapps") | |
for userenv in UserEnv.objects.all(): | |
with transaction.atomic(): | |
planet = Planet.objects.filter(company=userenv.company).first() | |
if planet: | |
try: | |
World.objects.get(userenv=userenv) | |
World.objects.filter(userenv=userenv).update( | |
planet=planet, | |
title=userenv.title, | |
status=World.STATUSES.active | |
) | |
except World.DoesNotExist: | |
World.objects.create( | |
userenv=userenv, | |
planet=planet, | |
title=userenv.title, | |
status=World.STATUSES.active | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 2 to Line 5 -> Fixes: Create a Skylabapps Planet related to its company
Line 6 to Line 23 ->Fixes: Create a World for every Planet by iterating all UserEnvs