-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate_funmash.py
40 lines (28 loc) · 940 Bytes
/
populate_funmash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'funmash.settings')
import django
django.setup()
from funmash_app.models import Image
from django.conf import settings
def populate():
images = {}
#change if you want to add all pictures
for x in range(1,17):
id = str(x) + ".jpg"
#The one line below is these three lines combined:
#images["name"]= "1 ("+x+").jpg",
#images["source"] = settings.MEDIA_URL+"/"+id
#images["ranking"] = x+1
add_img(str(x), settings.MEDIA_URL+id, x+1, "Nobilitie")
print("added" + settings.MEDIA_URL + id)
def add_img(name,source,ranking,ownerName):
img = Image.objects.get_or_create(name=name)[0]
img.source = source
img.ranking = ranking
img.owner = ownerName
img.save()
return img
# Start execution here!
if __name__ == '__main__':
print("Starting Funmash population script...")
populate()