mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2024-11-17 06:19:26 +08:00
Improved postmigration data seeding for equipments
This commit is contained in:
parent
9443631102
commit
6d25157c5f
1 changed files with 38 additions and 12 deletions
|
@ -43,15 +43,41 @@ class EquipmentInstance(models.Model):
|
||||||
@receiver(post_migrate)
|
@receiver(post_migrate)
|
||||||
def create_superuser(sender, **kwargs):
|
def create_superuser(sender, **kwargs):
|
||||||
if sender.name == 'equipments':
|
if sender.name == 'equipments':
|
||||||
|
equipment_data = [
|
||||||
|
{
|
||||||
|
'name': 'Pyrex Beaker',
|
||||||
|
'description': '',
|
||||||
|
'category': 'Glassware',
|
||||||
|
'remarks': 'First beaker of equipment tracker!'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'Bunsen Burner',
|
||||||
|
'description': '',
|
||||||
|
'category': 'Miscellaneous',
|
||||||
|
'remarks': 'First bunsen burner of equipment tracker!'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'Microscope',
|
||||||
|
'description': '',
|
||||||
|
'category': 'Miscellaneous',
|
||||||
|
'remarks': 'First microscope of equipment tracker!'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
for data in equipment_data:
|
||||||
EQUIPMENT, CREATED = Equipment.objects.get_or_create(
|
EQUIPMENT, CREATED = Equipment.objects.get_or_create(
|
||||||
name="Pyrex Beaker", description="", category="Glassware")
|
name=data['name'],
|
||||||
EQUIPMENT_INSTANCE, CREATED = EquipmentInstance.objects.get_or_create(
|
description=data['description'],
|
||||||
equipment=EQUIPMENT, status="Available", remarks="First beaker of equipment tracker!")
|
category=data['category']
|
||||||
EQUIPMENT, CREATED = Equipment.objects.get_or_create(
|
)
|
||||||
name="Bunsen Burner", description="", category="Miscellaneous")
|
if (CREATED):
|
||||||
EQUIPMENT_INSTANCE, CREATED = EquipmentInstance.objects.get_or_create(
|
print('Created Equipment: ' + data['name'])
|
||||||
equipment=EQUIPMENT, status="Available", remarks="First bunsen burner of equipment tracker!")
|
# Generate 3 equipment instances per SKU
|
||||||
EQUIPMENT, CREATED = Equipment.objects.get_or_create(
|
for x in range(3):
|
||||||
name="Microscope", description="", category="Miscellaneous")
|
EQUIPMENT_INSTANCE = EquipmentInstance.objects.create(
|
||||||
EQUIPMENT_INSTANCE, CREATED = EquipmentInstance.objects.get_or_create(
|
equipment=EQUIPMENT,
|
||||||
equipment=EQUIPMENT, status="Available", remarks="First microscope of equipment tracker!")
|
status='Available',
|
||||||
|
remarks=data['remarks']
|
||||||
|
)
|
||||||
|
print('Created Equipment Instances: ' +
|
||||||
|
EQUIPMENT_INSTANCE.equipment.name)
|
||||||
|
|
Loading…
Reference in a new issue