Skip to content

Instantly share code, notes, and snippets.

@reg3x
Last active May 27, 2020 16:03
Show Gist options
  • Save reg3x/e1efe559b2b46d3fa404a67a61ba57ad to your computer and use it in GitHub Desktop.
Save reg3x/e1efe559b2b46d3fa404a67a61ba57ad to your computer and use it in GitHub Desktop.
[create worlds] method to create worls #skylab
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
)
@reg3x
Copy link
Author

reg3x commented May 6, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment