diff options
author | luxagraf <sng@luxagraf.net> | 2017-09-29 14:25:22 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2017-09-29 14:25:22 -0500 |
commit | 8b1987da496bde09a66e32c44a296621fe779f5b (patch) | |
tree | 293e8ec0b10e2ac424a611fbf3865b87d08bd4bd /app | |
parent | 44f53429a7d27f45a6d19236b13493718273fe3a (diff) |
added auto-location to photo uploads
Diffstat (limited to 'app')
-rw-r--r-- | app/photos/models.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/photos/models.py b/app/photos/models.py index 039ce47..603e2d1 100644 --- a/app/photos/models.py +++ b/app/photos/models.py @@ -164,6 +164,18 @@ class LuxImage(models.Model): else: return False + def save(self): + if not self.point: + self.point = LuxImage.objects.latest().point + try: + self.location = Location.objects.filter( + geometry__contains=self.point + ).get() + except Location.DoesNotExist: + raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL)) + super(LuxImage, self).save() + + @receiver(post_save, sender=LuxImage) def post_save_events(sender, update_fields, created, instance, **kwargs): if instance.exif_raw == '': |