This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopulate-database.py
36 lines (27 loc) · 1.93 KB
/
populate-database.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
#!/usr/bin/env python
# Not the best long-term way to run scripts for a Django site, but this is just
# a temporary script to help during development.
# https://stackoverflow.com/questions/16853649/how-to-execute-a-python-script-from-the-django-shell
import os, django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings")
django.setup()
from projects.models import Author, Platform, Project, Publication, Tag
aut1, created = Author.objects.get_or_create(name="author_1", email="[email protected]")
aut2, created = Author.objects.get_or_create(name="author_2", email="[email protected]")
aut3, created = Author.objects.get_or_create(name="author_3", email="[email protected]")
tag1, created = Tag.objects.get_or_create(name="tag_1")
tag2, created = Tag.objects.get_or_create(name="tag_2")
tag3, created = Tag.objects.get_or_create(name="tag_3")
pub1, created = Publication.objects.get_or_create(doi="10.1000/1", title="publication 1")
pub2, created = Publication.objects.get_or_create(doi="10.1000/2", title="publication 2")
pub3, created = Publication.objects.get_or_create(doi="10.1000/3", title="publication 3")
plat1, created = Platform.objects.get_or_create(name="GitHub", url="https://github.com/")
plat2, created = Platform.objects.get_or_create(name="GitLab", url="https://gitlab.com/")
proj1, created = Project.objects.get_or_create(name="project_1", url="https://example.com/1/", author=Author.objects.get(id=1), platform=Platform.objects.get(name="GitHub"))
proj2, created = Project.objects.get_or_create(name="project_2", url="https://example.com/2/", author=Author.objects.get(id=2), platform=Platform.objects.get(name="GitHub"))
proj3, created = Project.objects.get_or_create(name="project_3", url="https://example.com/3/", author=Author.objects.get(id=3), platform=Platform.objects.get(name="GitLab"))
proj1.publications.add(pub1)
proj2.publications.add(pub2)
proj3.publications.add(pub3)
proj1.tags.add(tag1, tag2)
proj2.tags.add(tag3)