summaryrefslogtreecommitdiff
path: root/app/birds
diff options
context:
space:
mode:
Diffstat (limited to 'app/birds')
-rw-r--r--app/birds/__init__.py0
-rw-r--r--app/birds/aba_importer.py17
-rw-r--r--app/birds/admin.py19
-rw-r--r--app/birds/models.py43
4 files changed, 79 insertions, 0 deletions
diff --git a/app/birds/__init__.py b/app/birds/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/birds/__init__.py
diff --git a/app/birds/aba_importer.py b/app/birds/aba_importer.py
new file mode 100644
index 0000000..e5df528
--- /dev/null
+++ b/app/birds/aba_importer.py
@@ -0,0 +1,17 @@
+for row_index in range(sheet.nrows):
+ if sheet.cell(row_index,0).value != '':
+ sci = sheet.cell(row_index, 0).value.split("(")[1].split(")")[0]
+ bc = BirdClass.objects.get(scientific_name__exact=sci)
+ common_name = sheet.cell(row_index, 1).value
+ sci_name = sheet.cell(row_index, 2).value
+ code = int(sheet.cell(row_index, 3).value)
+ bclass = bc
+ #create bird here
+ b, created = Bird.objects.get_or_create(
+ common_name = common_name,
+ scientific_name = sci_name,
+ code = code,
+ bird_class = bc
+ )
+ print(b)
+
diff --git a/app/birds/admin.py b/app/birds/admin.py
new file mode 100644
index 0000000..a67b358
--- /dev/null
+++ b/app/birds/admin.py
@@ -0,0 +1,19 @@
+from django.contrib import admin
+from django.contrib.gis.admin import OSMGeoAdmin
+from birds.models import BirdSighting, BirdClass, Bird
+
+
+class BirdClassAdmin(admin.ModelAdmin):
+ list_display = ('common_name', 'scientific_name',)
+
+class BirdAdmin(admin.ModelAdmin):
+ list_display = ('pk','common_name', 'scientific_name','code','bird_class')
+
+
+class BirdSightingAdmin(OSMGeoAdmin):
+ list_display = ('bird', 'location',)
+ list_filter = ('location',)
+
+admin.site.register(BirdSighting, BirdSightingAdmin)
+admin.site.register(BirdClass, BirdClassAdmin)
+admin.site.register(Bird, BirdAdmin)
diff --git a/app/birds/models.py b/app/birds/models.py
new file mode 100644
index 0000000..4f7ae51
--- /dev/null
+++ b/app/birds/models.py
@@ -0,0 +1,43 @@
+import datetime
+from django.contrib.gis.db import models
+from locations.models import BirdingLocation
+
+def get_upload_path(self, filename):
+ return "images/bird-images/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename)
+
+#from http://aba.org/checklist/codes.html
+ABA_CODES = (
+ (1, 'regular occurring - common'),
+ (2, 'regular occurring - less common'),
+ (3, 'rare'),
+ (4, 'casual'),
+ (5, 'accidental'),
+ (6, 'Cannot be found'),
+ )
+
+
+class BirdClass(models.Model):
+ common_name = models.CharField(max_length=200)
+ scientific_name = models.CharField(max_length=200)
+
+ class Meta:
+ verbose_name_plural = 'Bird Class'
+
+ def __str__(self):
+ return self.common_name
+
+class Bird(models.Model):
+ common_name = models.CharField(max_length=200)
+ scientific_name = models.CharField(max_length=200)
+ code = models.IntegerField(choices=ABA_CODES, default=0)
+ bird_class = models.ForeignKey(BirdClass)
+
+ def __str__(self):
+ return self.common_name
+
+class BirdSighting(models.Model):
+ bird = models.ForeignKey(Bird)
+ location = models.ForeignKey(BirdingLocation)
+ date = models.DateTimeField('Date')
+ image = models.FileField(upload_to=get_upload_path, null=True,blank=True)
+