2016-09-18 02:29:00 +03:00
|
|
|
from .models import Character, Faction, Ship
|
|
|
|
|
|
|
|
|
|
|
|
def initialize():
|
2019-06-11 06:54:30 +03:00
|
|
|
human = Character(name="Human")
|
2016-09-18 02:29:00 +03:00
|
|
|
human.save()
|
|
|
|
|
2019-06-11 06:54:30 +03:00
|
|
|
droid = Character(name="Droid")
|
2016-09-18 02:29:00 +03:00
|
|
|
droid.save()
|
|
|
|
|
2019-06-11 06:54:30 +03:00
|
|
|
rebels = Faction(id="1", name="Alliance to Restore the Republic", hero=human)
|
2016-09-18 02:29:00 +03:00
|
|
|
rebels.save()
|
|
|
|
|
2019-06-11 06:54:30 +03:00
|
|
|
empire = Faction(id="2", name="Galactic Empire", hero=droid)
|
2016-09-18 02:29:00 +03:00
|
|
|
empire.save()
|
|
|
|
|
2019-06-11 06:54:30 +03:00
|
|
|
xwing = Ship(id="1", name="X-Wing", faction=rebels)
|
2016-09-18 02:29:00 +03:00
|
|
|
xwing.save()
|
|
|
|
|
2016-09-22 05:32:39 +03:00
|
|
|
human.ship = xwing
|
|
|
|
human.save()
|
|
|
|
|
2019-06-11 06:54:30 +03:00
|
|
|
ywing = Ship(id="2", name="Y-Wing", faction=rebels)
|
2016-09-18 02:29:00 +03:00
|
|
|
ywing.save()
|
|
|
|
|
2019-06-11 06:54:30 +03:00
|
|
|
awing = Ship(id="3", name="A-Wing", faction=rebels)
|
2016-09-18 02:29:00 +03:00
|
|
|
awing.save()
|
|
|
|
|
|
|
|
# Yeah, technically it's Corellian. But it flew in the service of the rebels,
|
|
|
|
# so for the purposes of this demo it's a rebel ship.
|
2023-09-06 10:29:58 +03:00
|
|
|
falcon = Ship(id="4", name="Millennium Falcon", faction=rebels)
|
2016-09-18 02:29:00 +03:00
|
|
|
falcon.save()
|
|
|
|
|
2019-06-11 06:54:30 +03:00
|
|
|
homeOne = Ship(id="5", name="Home One", faction=rebels)
|
2016-09-18 02:29:00 +03:00
|
|
|
homeOne.save()
|
|
|
|
|
2019-06-11 06:54:30 +03:00
|
|
|
tieFighter = Ship(id="6", name="TIE Fighter", faction=empire)
|
2016-09-18 02:29:00 +03:00
|
|
|
tieFighter.save()
|
|
|
|
|
2019-06-11 06:54:30 +03:00
|
|
|
tieInterceptor = Ship(id="7", name="TIE Interceptor", faction=empire)
|
2016-09-18 02:29:00 +03:00
|
|
|
tieInterceptor.save()
|
|
|
|
|
2019-06-11 06:54:30 +03:00
|
|
|
executor = Ship(id="8", name="Executor", faction=empire)
|
2016-09-18 02:29:00 +03:00
|
|
|
executor.save()
|
|
|
|
|
|
|
|
|
|
|
|
def create_ship(ship_name, faction_id):
|
2019-06-11 06:54:30 +03:00
|
|
|
new_ship = Ship(name=ship_name, faction_id=faction_id)
|
2016-09-18 02:29:00 +03:00
|
|
|
new_ship.save()
|
|
|
|
return new_ship
|
|
|
|
|
|
|
|
|
|
|
|
def get_ship(_id):
|
|
|
|
return Ship.objects.get(id=_id)
|
|
|
|
|
|
|
|
|
|
|
|
def get_ships():
|
|
|
|
return Ship.objects.all()
|
|
|
|
|
|
|
|
|
|
|
|
def get_faction(_id):
|
|
|
|
return Faction.objects.get(id=_id)
|
|
|
|
|
|
|
|
|
|
|
|
def get_rebels():
|
|
|
|
return get_faction(1)
|
|
|
|
|
|
|
|
|
|
|
|
def get_empire():
|
|
|
|
return get_faction(2)
|