Skip to content

Commit

Permalink
Merge pull request #103 from gm3dmo/w60
Browse files Browse the repository at this point in the history
Adding soldiers
gm3dmo authored Nov 8, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 75272e7 + 1488b16 commit 6fa9222
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmp/models.py
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ class Soldier(models.Model):
surname = models.CharField(max_length=255, unique=False, default='')
initials = models.CharField(max_length=255, unique=False, default='')
army_number = models.CharField(max_length=255, unique=False, default='')
rank = models.ForeignKey('Rank', on_delete=models.CASCADE)
rank = models.ForeignKey('Rank', on_delete=models.CASCADE, related_name='ranks')
notes = models.CharField(max_length=255, unique=False, default='')

def __str__(self):
2 changes: 1 addition & 1 deletion railway.json
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python manage.py makemigrations && python manage.py migrate && python manage.py runscript delete-all-countries && python manage.py runscript insert-all-countries && python manage.py runscript add-flags-to-countries && python manage.py runscript insert-all-pow-camps && python manage.py runscript insert-all-decorations && python manage.py runscript insert-all-companies && python manage.py collectstatic && python manage.py runserver 0.0.0.0:$PORT",
"startCommand": "python manage.py makemigrations && python manage.py migrate && python manage.py runscript delete-all-countries && python manage.py runscript insert-all-countries && python manage.py runscript add-flags-to-countries && python manage.py runscript insert-all-pow-camps && python manage.py runscript insert-all-decorations && python manage.py runscript insert-all-companies python manage.py runscript insert-all-soldiers && python manage.py collectstatic && python manage.py runserver 0.0.0.0:$PORT",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
5 changes: 5 additions & 0 deletions scripts/delete-all-soldiers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from cmp.models import Soldier

def run():
Ranks = Soldier.objects.all()
Ranks.delete()
33 changes: 33 additions & 0 deletions scripts/insert-all-soldiers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

def run():

import sys
import urllib3
import csv
from cmp.models import Soldier

ref_data_url = "https://raw.githubusercontent.com/gm3dmo/old-cmp/main/data/soldier.csv"
http = urllib3.PoolManager()
r = http.request('GET', ref_data_url)
print(r.status)
# load the response into a csv dictionary reader
reader = csv.DictReader(r.data.decode('utf-8').splitlines())
# breakpoint()
print(reader)
# print(reader.fieldnames)
for row in reader:
# id,surname,initials,army_number,rank_id,notes
print(f"""{row['id']} {row['surname']}""")
try:
Soldier.objects.create(
id = row['id'],
surname = row['surname'],
initials = row['initials'],
army_number = row['army_number'],
rank_id = row['rank_id'],
notes = row['notes']
)
except Exception as e:
print("Error with: " + row['surname'])

raise e

0 comments on commit 6fa9222

Please sign in to comment.