From 3e44f5baa53f2ae53d039070eb998c96b639411b Mon Sep 17 00:00:00 2001 From: mortenwh Date: Tue, 5 Feb 2019 17:02:53 +0100 Subject: [PATCH] #1: Added default None in search model, created migration, and updated search in viewer.views.IndexView.render --- .../migrations/0007_auto_20190205_1546.py | 28 +++++++++++++++++++ geospaas/viewer/models.py | 6 ++-- geospaas/viewer/views.py | 12 ++++---- 3 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 geospaas/viewer/migrations/0007_auto_20190205_1546.py diff --git a/geospaas/viewer/migrations/0007_auto_20190205_1546.py b/geospaas/viewer/migrations/0007_auto_20190205_1546.py new file mode 100644 index 00000000..d34f6b23 --- /dev/null +++ b/geospaas/viewer/migrations/0007_auto_20190205_1546.py @@ -0,0 +1,28 @@ +# Generated by Django 2.1.5 on 2019-02-05 15:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('viewer', '0006_auto_20190204_1345'), + ] + + operations = [ + migrations.AlterField( + model_name='search', + name='instrument', + field=models.ManyToManyField(blank=True, default=None, to='vocabularies.Instrument'), + ), + migrations.AlterField( + model_name='search', + name='parameter', + field=models.ManyToManyField(blank=True, default=None, to='vocabularies.Parameter'), + ), + migrations.AlterField( + model_name='search', + name='platform', + field=models.ManyToManyField(blank=True, default=None, to='vocabularies.Platform'), + ), + ] diff --git a/geospaas/viewer/models.py b/geospaas/viewer/models.py index 13243c21..bbf919e2 100644 --- a/geospaas/viewer/models.py +++ b/geospaas/viewer/models.py @@ -19,9 +19,9 @@ class Search(geomodels.Model): sdate = models.DateTimeField() # when was search date0 = models.DateField() date1 = models.DateField() - platform = models.ManyToManyField(Platform, blank=True) - instrument = models.ManyToManyField(Instrument, blank=True) - parameter = models.ManyToManyField(Parameter, blank=True) + platform = models.ManyToManyField(Platform, blank=True, default=None) + instrument = models.ManyToManyField(Instrument, blank=True, default=None) + parameter = models.ManyToManyField(Parameter, blank=True, default=None) # GeoDjango-specific: a geometry field (PolygonField), and # overriding the default manager with a GeoManager instance. diff --git a/geospaas/viewer/views.py b/geospaas/viewer/views.py index e679e4e7..bea79d28 100644 --- a/geospaas/viewer/views.py +++ b/geospaas/viewer/views.py @@ -72,16 +72,16 @@ def render(self, request): datasets = datasets.order_by('time_coverage_start') if self.form.cleaned_data['platform'] is not None and \ len(self.form.cleaned_data['platform'])>0: - src = self.form.cleaned_data['platform'] - datasets = datasets.filter(sources__platform__in=src) + platform = self.form.cleaned_data['platform'][0] + datasets = datasets.filter(sources__platform=platform) if self.form.cleaned_data['instrument'] is not None and \ len(self.form.cleaned_data['instrument'])>0: - src = self.form.cleaned_data['instrument'] - datasets = datasets.filter(sources__instrument__in=src) + instr = self.form.cleaned_data['instrument'][0] + datasets = datasets.filter(sources__instrument=instr) if self.form.cleaned_data['parameter'] is not None and \ len(self.form.cleaned_data['parameter'])>0: - src = self.form.cleaned_data['parameter'] - datasets = datasets.filter(parameters__in=src) + par = self.form.cleaned_data['parameter'][0] + datasets = datasets.filter(parameters=par) t0 = self.form.cleaned_data['date0'] t1 = self.form.cleaned_data['date1'] + timezone.timedelta(hours=24) datasets = datasets.filter(