Import old cards and link to members

This commit is contained in:
2020-01-09 06:45:32 +00:00
parent aa6c81c48c
commit 1bf5dd182c
4 changed files with 57 additions and 9 deletions
+27
View File
@@ -30,6 +30,15 @@ TRANSACTION_FIELDS = [
'info_source',
]
CARD_FIELDS = [
'id',
'member_id',
'card_number',
'notes',
'last_seen_at',
'active_status',
]
print('Deleting all members...')
models.Member.objects.all().delete()
@@ -66,4 +75,22 @@ for t in old_transactions:
))
print('Deleting all cards...')
models.Card.objects.all().delete()
print('Importing old cards...')
old_cards = old_models.AccessKeys.objects.using('old_portal').all()
for c in old_cards:
new_card = {}
for f in CARD_FIELDS:
new_card[f] = c.__dict__.get(f, None)
models.Card.objects.create(**new_card)
print('Imported #{} - {} {}'.format(
c.id, c.card_number, c.notes
))
print('Done.')