korvinos / django-fun

0 stars 0 forks source link

Create view for data list display #12

Open korvinos opened 7 years ago

korvinos commented 7 years ago

We are going to keep all business logic in a view function (so far)

korvinos commented 7 years ago

https://www.w3schools.com/

AlfaAli commented 7 years ago

I created a simple function in views which import models from geospass project:

-----------------------------------------

from django.http import HttpResponse

Create your views here.

---

import os, sys os.environ['DJANGO_SETTINGS_MODULE'] = 'geospaas_project.settings' sys.path.insert(0, '/vagrant/shared/course_vm/geospaas_project/') # import django django.setup() # from django.conf import settings from geospaas.catalog.models import Dataset

from geospaas.catalog.models import DatasetURI

def read_data(request):

search by instrument

  ds = Dataset.objects.filter(source__instrument__short_name='MODIS')
  output = ';  '.join([str(d.time_coverage_start) for d in ds])
  return HttpResponse(output)

------------------------------------------------------------------

So I am getting an error when try to import models from geo-spaas project, something like this

In [10]: from geospaas.catalog.models import Dataset

RuntimeError Traceback (most recent call last)

in () ----> 1 from geospaas.catalog.models import Dataset /home/vagrant/miniconda/lib/python2.7/site-packages/geospaas/catalog/models.py in () 8 from django.utils.translation import ugettext as _ 9 ---> 10 from geospaas.vocabularies.models import Parameter 11 from geospaas.vocabularies.models import ScienceKeyword 12 from geospaas.vocabularies.models import Platform /home/vagrant/miniconda/lib/python2.7/site-packages/geospaas/vocabularies/models.py in () 16 # nersc-metadata package 17 ---> 18 class Platform(models.Model): 19 20 category = models.CharField(max_length=100) /home/vagrant/miniconda/lib/python2.7/site-packages/django/db/models/base.pyc in __new__(cls, name, bases, attrs) 100 "Model class %s.%s doesn't declare an explicit " 101 "app_label and isn't in an application in " --> 102 "INSTALLED_APPS." % (module, name) 103 ) 104 RuntimeError: Model class geospaas.vocabularies.models.Platform doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
AlfaAli commented 7 years ago

I solved by adding to th installed apps the following:

'

INSTALLED_APPS = [ 'geospaas.catalog',

END ANSIBLE MANAGED BLOCK geospaas.catalog

# BEGIN ANSIBLE MANAGED BLOCK geospaas.vocabularies
'geospaas.vocabularies',
'geospass_fun',
'blog.apps.BlogConfig',    ....

So

ds = Dataset.objects.filter(sourceinstrumentshort_name='MODIS')

works, but output = '; '.join([str(d.time_coverage_start) for d in ds])

gives the error: OperationalError: no such table: catalog_dataset