summaryrefslogtreecommitdiff
path: root/app/sightings/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/sightings/models.py')
-rw-r--r--app/sightings/models.py74
1 files changed, 35 insertions, 39 deletions
diff --git a/app/sightings/models.py b/app/sightings/models.py
index fe09f39..5723776 100644
--- a/app/sightings/models.py
+++ b/app/sightings/models.py
@@ -130,6 +130,12 @@ class Sighting(models.Model):
point = models.PointField(blank=True)
location = models.ForeignKey(Location, on_delete=models.CASCADE, blank=True)
pub_date = models.DateTimeField('Date', default=timezone.now)
+ location_name = models.CharField(max_length=200, blank=True)
+ state_name = models.CharField(max_length=200, blank=True)
+ country_name = models.CharField(max_length=200, blank=True)
+ country_slug = models.CharField(max_length=200, blank=True)
+ region_name = models.CharField(max_length=200, blank=True)
+ ap_common_name = models.CharField(max_length=200, blank=True)
# seen_by = models.ManyToManyField(User)
# images = models.ManyToManyField(LuxImage, blank=True)
# audio = models.ManyToManyField(BirdAudio, blank=True)
@@ -183,7 +189,7 @@ class Sighting(models.Model):
return reverse("sightings:detail", kwargs={"slug": self.ap.slug})
def __str__(self):
- return self.ap.common_name
+ return self.ap_common_name
def save(self, *args, **kwargs):
if not self.point:
@@ -194,44 +200,34 @@ class Sighting(models.Model):
).get()
except Location.DoesNotExist:
raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL))
+ self.ap_common_name = self.ap.common_name
+ self.location_name = self.location.name
+ self.state_name = self.location.state.name
+ self.country_name = self.location.state.country.name
+ self.country_slug = self.location.state.country.slug
+ self.region_name = self.location.state.country.lux_region.name
super(Sighting, self).save()
-"""
-Migration from Birds to abstract:
-apclass = OLDAPClass.objects.all()
-for b in apclass:
- NewAPClass.objects.create(
- common_name = b.common_name,
- scientific_name = b.scientific_name,
- kind = 1
- )
-
-ap = OLDAP.objects.all()
-for b in ap:
- apnew = NewAPClass.objects.get(scientific_name=b.apclass.scientific_name)
- print(ap)
- NewAP.objects.create(
- common_name = b.common_name,
- scientific_name = b.scientific_name,
- code = b.code,
- apclass = apnew,
- image = b.image,
- image_credit = b.image_credit,
- )
- print(t)
-
-oldsighting = OLDSighting.objects.all()
-for bird in oldsighting:
- ap = NEWAP.objects.get(scientific_name=bird.ap.scientific_name)
- s = NEWSighting.objects.create(
- ap = ap,
- point = bird.point,
- location = bird.location,
- date = bird.date,
- )
- for t in bird.images.all():
- s.images.add(t)
- for t in bird.seen_by.all():
- s.seen_by.add(t)
-"""
+class FieldNote(models.Model):
+ sighting = models.ForeignKey(Sighting, on_delete=models.CASCADE)
+ body_html = models.TextField(blank=True)
+ body_markdown = models.TextField(blank=True)
+ # these are only used to speed up admin
+ sighting_pub_date = models.DateTimeField('Date', blank=True)
+ sighting_location = models.CharField(max_length=200, blank=True)
+ ap_common_name = models.CharField(max_length=200, blank=True)
+
+ class Meta:
+ ordering = ["sighting_pub_date", ]
+
+ def __str__(self):
+ return '%s %s' % (self.ap_common_name, self.pk)
+
+ def save(self, *args, **kwargs):
+ self.sighting_pub_date = self.sighting.pub_date
+ self.ap_common_name = self.sighting.ap.common_name
+ self.sighting_location = self.sighting.location_name
+ md = render_images(self.body_markdown)
+ self.body_html = markdown_to_html(md)
+ super(FieldNote, self).save()