Commit 4c95de8a authored by Rafal's avatar Rafal

Make apitype

Add all apis to database
parent ce180e5d
from app.API.models import API from app.API.models import API, APIType
from app.Tag.models import Tag from app.Tag.models import Tag
__author__ = 'Rafal' __author__ = 'Rafal'
...@@ -10,14 +10,20 @@ class Command(BaseCommand): ...@@ -10,14 +10,20 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
apis = [ apis = [
['Hotele w Krakowie', 'Krakow'], ['Apteki w Krakowie', 'Krakow', 'map', 'apteki'],
['Wypadki w Krakowie', 'Krakow'], ['Baseny w Krakowie', 'Krakow', 'map', 'baseny'],
['Cmenatarze w Krakowie', 'Krakow'], ['Hotele w Krakowie', 'Krakow', 'map',' hotele'],
['HotSpoty w Krakowie', 'Krakow', 'map',' mapaHotSpotow'],
['Utrudnienia w Krakowie', 'Krakow', 'map',' mapaUtrudnien'],
['Restauracje w Krakowie', 'Krakow', 'map',' restauracje'],
['Szpitale w Krakowie', 'Krakow', 'map',' szpitale'],
['Zdarzenia drogowe w Krakowie', 'Krakow', 'map',' zdarzeniaDrogowe'],
] ]
print "Creating APIs" print "Creating APIs"
for api in apis: for api in apis:
print "Create {0}".format(api[0]) print "Create {0}".format(api[0])
tag = Tag.objects.filter(name=api[1])[0] tag = Tag.objects.filter(name=api[1])[0]
new_api = API.objects.create(name=api[0]) api_type = APIType.objects.filter(name=api[2])[0]
new_api = API.objects.create(name=api[0], type=api_type, source=api[3])
new_api.tag = [tag, ] new_api.tag = [tag, ]
new_api.save() new_api.save()
\ No newline at end of file
from app.API.models import API, APIType
from app.Tag.models import Tag
__author__ = 'Rafal'
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'Closes the specified poll for voting'
def handle(self, *args, **options):
apis_type = [
['map', ],
]
print "Creating APIs type"
for api_type in apis_type:
print "Create {0}".format(api_type[0])
new_api = APIType.objects.create(name=api_type[0])
new_api.save()
\ No newline at end of file
...@@ -5,9 +5,22 @@ from django.db import models ...@@ -5,9 +5,22 @@ from django.db import models
from app.Tag.models import Tag from app.Tag.models import Tag
class APIType(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class API(models.Model): class API(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
tag = models.ManyToManyField(Tag, related_name='API_tags', blank=False, default=None) tag = models.ManyToManyField(Tag, related_name='API_tags', blank=False, default=None)
type = models.ForeignKey(APIType, related_name='API_type',
blank=False, null=False, default=None)
source = models.CharField(max_length=100)
def __str__(self): def __str__(self):
return self.name return self.name
...@@ -10,6 +10,7 @@ class Command(BaseCommand): ...@@ -10,6 +10,7 @@ class Command(BaseCommand):
call_command('init_users') call_command('init_users')
call_command('init_localizations') call_command('init_localizations')
call_command('init_tags') call_command('init_tags')
call_command('init_apitypes')
call_command('init_apis') call_command('init_apis')
call_command('init_textmessages') call_command('init_textmessages')
call_command('init_discussions') call_command('init_discussions')
......
...@@ -14,8 +14,8 @@ class Command(BaseCommand): ...@@ -14,8 +14,8 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
apis = [ apis = [
['admin', 'Hotele w Krakowie'], ['admin', 'Hotele w Krakowie'],
['admin', 'Wypadki w Krakowie'], ['admin', 'Zdarzenia drogowe w Krakowie'],
['admin', 'Cmenatarze w Krakowie'], ['admin', 'Restauracje w Krakowie'],
] ]
print "Creating UserApi" print "Creating UserApi"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment