Commit ad0f8d46 authored by Rafal's avatar Rafal

Add media root + change icon_www to icon -> using ImageField

parent 73af1f0a
...@@ -13,7 +13,7 @@ import os ...@@ -13,7 +13,7 @@ import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
...@@ -131,3 +131,5 @@ TEMPLATES = [ ...@@ -131,3 +131,5 @@ TEMPLATES = [
}, },
}, },
] ]
MEDIA_URL = '/media/'
\ No newline at end of file
...@@ -2,9 +2,11 @@ from django.conf.urls import patterns, include, url ...@@ -2,9 +2,11 @@ from django.conf.urls import patterns, include, url
from django.contrib import admin from django.contrib import admin
from rest_framework.authtoken import views as token_view from rest_framework.authtoken import views as token_view
from rest_framework import routers from rest_framework import routers
from JoinTheCityREST import settings
router = routers.DefaultRouter() router = routers.DefaultRouter()
from django.conf.urls.static import static
from app.API import views as api_views from app.API import views as api_views
from app.Discussion import views as discussion_views from app.Discussion import views as discussion_views
from app.Event import views as event_views from app.Event import views as event_views
...@@ -39,4 +41,4 @@ urlpatterns = [ ...@@ -39,4 +41,4 @@ urlpatterns = [
namespace='rest_framework')), namespace='rest_framework')),
url(r'^api-token-auth/', token_view.obtain_auth_token), url(r'^api-token-auth/', token_view.obtain_auth_token),
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
] ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.core.files import File
from app.API.models import API, APIType from app.API.models import API, APIType
from app.Tag.models import Tag from app.Tag.models import Tag
...@@ -10,20 +11,21 @@ class Command(BaseCommand): ...@@ -10,20 +11,21 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
apis = [ apis = [
['Apteki w Krakowie', 'Krakow', 'map', 'apteki', '', 'Opis API o aptekach w Krakowie'], ['Apteki w Krakowie', 'Krakow', 'map', 'apteki', 'image/icon.jpg', 'Opis API o aptekach w Krakowie'],
['Baseny w Krakowie', 'Krakow', 'map', 'baseny', '', 'Opis API o aptekach w Krakowie'], ['Baseny w Krakowie', 'Krakow', 'map', 'baseny', 'image/icon.jpg', 'Opis API o aptekach w Krakowie'],
['Hotele w Krakowie', 'Krakow', 'map',' hotele', '', 'Opis API o aptekach w Krakowie'], ['Hotele w Krakowie', 'Krakow', 'map',' hotele', 'image/icon.jpg', 'Opis API o aptekach w Krakowie'],
['HotSpoty w Krakowie', 'Krakow', 'map',' mapaHotSpotow', '', 'Opis API o aptekach w Krakowie'], ['HotSpoty w Krakowie', 'Krakow', 'map',' mapaHotSpotow', 'image/icon.jpg', 'Opis API o aptekach w Krakowie'],
['Utrudnienia w Krakowie', 'Krakow', 'map',' mapaUtrudnien', '', 'Opis API o aptekach w Krakowie'], ['Utrudnienia w Krakowie', 'Krakow', 'map',' mapaUtrudnien', 'image/icon.jpg', 'Opis API o aptekach w Krakowie'],
['Restauracje w Krakowie', 'Krakow', 'map',' restauracje', '', 'Opis API o aptekach w Krakowie'], ['Restauracje w Krakowie', 'Krakow', 'map',' restauracje', 'image/icon.jpg', 'Opis API o aptekach w Krakowie'],
['Szpitale w Krakowie', 'Krakow', 'map',' szpitale', '', 'Opis API o aptekach w Krakowie'], ['Szpitale w Krakowie', 'Krakow', 'map',' szpitale', 'image/icon.jpg', 'Opis API o aptekach w Krakowie'],
['Zdarzenia drogowe w Krakowie', 'Krakow', 'map',' zdarzeniaDrogowe', '', 'Opis API o aptekach w Krakowie'], ['Zdarzenia drogowe w Krakowie', 'Krakow', 'map',' zdarzeniaDrogowe', 'image/icon.jpg', 'Opis API o aptekach w Krakowie'],
] ]
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]
api_type = APIType.objects.filter(name=api[2])[0] api_type = APIType.objects.filter(name=api[2])[0]
new_api = API.objects.create(name=api[0], type=api_type, source=api[3], icon_www=api[4], description = api[5]) new_api = API.objects.create(name=api[0], type=api_type, source=api[3] , description = api[5])
new_api.tag = [tag, ] new_api.tag = [tag, ]
new_api.icon = api[4]
new_api.save() new_api.save()
\ No newline at end of file
...@@ -18,7 +18,7 @@ class API(models.Model): ...@@ -18,7 +18,7 @@ class API(models.Model):
type = models.ForeignKey(APIType, related_name='API_type', type = models.ForeignKey(APIType, related_name='API_type',
blank=False, null=False, default=None) blank=False, null=False, default=None)
source = models.CharField(max_length=100) source = models.CharField(max_length=100)
icon_www = models.CharField(max_length=100, default=None, null=True, blank=True) icon = models.ImageField(null=True, blank=True)
description = models.CharField(max_length=300, default=None, null=True, blank=True) description = models.CharField(max_length=300, default=None, null=True, blank=True)
......
...@@ -6,7 +6,7 @@ class APISerializer(serializers.HyperlinkedModelSerializer): ...@@ -6,7 +6,7 @@ class APISerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = API model = API
fields = ('url', 'name', 'tag' ,'type', 'source', 'icon_www', 'description') fields = ('url', 'name', 'tag' ,'type', 'source', 'icon', 'description')
class APITypeSerializer(serializers.HyperlinkedModelSerializer): class APITypeSerializer(serializers.HyperlinkedModelSerializer):
......
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