Don't rely on manager in migration

This commit is contained in:
Adarnof 2017-12-22 11:19:53 -05:00
parent 856f1e176a
commit 6e4562b0e6
2 changed files with 5 additions and 8 deletions

View File

@ -20,8 +20,6 @@ def available_states_query(character):
class CharacterOwnershipManager(Manager):
use_in_migrations = True
def create_by_token(self, token):
if not EveCharacter.objects.filter(character_id=token.character_id).exists():
EveCharacter.objects.create_character(token.character_id)

View File

@ -107,12 +107,11 @@ def populate_ownerships(apps, schema_editor):
tokens = Token.objects.filter(character_id__in=unique_character_owners)
for c_id in unique_character_owners:
ts = tokens.filter(character_id=c_id).order_by('created')
for t in ts:
if t.refresh_token:
# find newest refreshable token and use it as basis for CharacterOwnership
CharacterOwnership.objects.create_by_token(t)
break
ts = tokens.filter(character_id=c_id).exclude(refresh_token__isnull=True).order_by('created')
if ts.exists():
token = ts[0]
CharacterOwnership.objects.create(user_id=token.user_id, character_id=token.character_id, owner_hash=token.character_owner_hash)
def create_profiles(apps, schema_editor):