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.py63
1 files changed, 49 insertions, 14 deletions
diff --git a/app/sightings/models.py b/app/sightings/models.py
index 80b9ba9..8531772 100644
--- a/app/sightings/models.py
+++ b/app/sightings/models.py
@@ -1,15 +1,25 @@
import datetime
+import re
from django.urls import reverse
from django.apps import apps
from django.template.defaultfilters import slugify
from django.contrib.gis.db import models
-from django.contrib.auth.models import User
+# from django.contrib.auth.models import User
from django.utils import timezone
-from locations.models import Location
from django import forms
from django.conf import settings
-from photos.models import LuxImage
+# from photos.models import LuxImage
+
+from locations.models import Location
+from utils.widgets import parse_image
+from utils.widgets import markdown_to_html
+from utils.next_prev import next_in_order, prev_in_order
+
+
+def render_images(s):
+ s = re.sub('<img(.*)/>', parse_image, s)
+ return s
def get_upload_path(self, filename):
@@ -48,6 +58,7 @@ class APClass(models.Model):
def __str__(self):
return self.common_name
+
class AP(models.Model):
common_name = models.CharField(max_length=200)
slug = models.SlugField()
@@ -56,8 +67,13 @@ class AP(models.Model):
apclass = models.ForeignKey(APClass, on_delete=models.CASCADE)
body_html = models.TextField(null=True, blank=True)
body_markdown = models.TextField(null=True, blank=True)
- #image = models.FileField(upload_to=get_upload_path, null=True, blank=True, help_text="width of high res is 1360px")
- #image_credit = models.CharField(max_length=200, blank=True, null=True)
+ # image = models.FileField(upload_to=get_upload_path, null=True, blank=True, help_text="width of high res is 1360px")
+ # image_credit = models.CharField(max_length=200, blank=True, null=True)
+
+ class Meta:
+ verbose_name_plural = 'Animal/Plant'
+ verbose_name = 'Animal/Plant'
+ ordering = ["common_name", ]
def __str__(self):
return self.common_name
@@ -71,10 +87,29 @@ class AP(models.Model):
def kind(self):
return self.apclass.kind
- class Meta:
- verbose_name_plural = 'Animal/Plant'
- verbose_name = 'Animal/Plant'
- ordering = ["common_name", ]
+ def get_prev(self):
+ model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name)
+ return prev_in_order(self, model.objects.all())
+
+ def get_next(self):
+ model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name)
+ return next_in_order(self, model.objects.all())
+
+ @property
+ def get_previous_admin_url(self):
+ model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name)
+ try:
+ return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=[self.get_prev().pk])
+ except model.DoesNotExist:
+ return ''
+
+ @property
+ def get_next_admin_url(self):
+ model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name)
+ try:
+ return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=[self.get_next().pk])
+ except model.DoesNotExist:
+ return ''
def save(self, *args, **kwargs):
if self.pk:
@@ -89,9 +124,9 @@ 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)
- #seen_by = models.ManyToManyField(User)
- #images = models.ManyToManyField(LuxImage, blank=True)
- #audio = models.ManyToManyField(BirdAudio, blank=True)
+ # seen_by = models.ManyToManyField(User)
+ # images = models.ManyToManyField(LuxImage, blank=True)
+ # audio = models.ManyToManyField(BirdAudio, blank=True)
class Meta:
ordering = ["-pub_date", ]
@@ -122,13 +157,13 @@ class Sighting(models.Model):
@property
def get_previous_admin_url(self):
n = self.get_previous_by_pub_date()
- return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[n.id] )
+ return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=[n.id])
@property
def get_next_admin_url(self):
model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name)
try:
- return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[self.get_next_by_pub_date().pk] )
+ return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=[self.get_next_by_pub_date().pk])
except model.DoesNotExist:
return ''