From f64f31dedada0f9c21bbaea77048fa907d6b4afd Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Thu, 4 Nov 2010 12:51:11 +0000 Subject: [PATCH] Save the EVEAccount instance before attempting to add characters to it. Since Django 1.2, the ORM needs to know what database the object belongs in before additions to their M2M fields. Saving the record before the character import solves the problem. --- eve_api/api_puller/accounts.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/eve_api/api_puller/accounts.py b/eve_api/api_puller/accounts.py index 277dfc0..4b5d0f6 100755 --- a/eve_api/api_puller/accounts.py +++ b/eve_api/api_puller/accounts.py @@ -72,14 +72,11 @@ def import_eve_account(api_key, user_id, force_cache=False): # Create or retrieve the account last to make sure everything # before here is good to go. - try: - account = EVEAccount.objects.get(id=user_id) - except EVEAccount.DoesNotExist: - account = EVEAccount(id=user_id) - + account, created = EVEAccount.objects.get_or_create(id=user_id) account.api_key = api_key account.api_user_id = user_id account.api_status = API_STATUS_OK + account.save() for node in characters_node_children: try: