Files
AdventureLog/backend/server/adventures/migrations/0074_contentimage_source_metadata.py
Sean Morley ab698ee8ba Add image source metadata and GPS coordinates handling for ContentImage
- Introduced a new `source` field in the `ContentImage` model to track the origin of images (e.g., upload, Google, Wikipedia, URL, Immich).
- Added a `source_url` field to store the URL associated with the image source.
- Implemented a `coordinates` field to store GPS data for images.
- Enhanced the `ContentImageSerializer` to include the new fields and updated the representation logic.
- Created a management command to backfill GPS coordinates for existing images based on EXIF data or Immich metadata.
- Added utility functions for resolving image metadata and creating `ContentImage` instances with proper source and coordinates.
- Updated various views and services to utilize the new image source and coordinates features.
- Added tests to ensure the correct functionality of the new features and metadata handling.
2026-06-30 20:38:59 -04:00

53 lines
1.5 KiB
Python

from django.contrib.gis.geos import Point
from django.db import migrations, models
import django.contrib.gis.db.models.fields
def backfill_image_source(apps, schema_editor):
ContentImage = apps.get_model('adventures', 'ContentImage')
ContentImage.objects.filter(immich_id__isnull=False).exclude(immich_id='').update(
source='immich'
)
def noop(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('adventures', '0073_pointfield_geography'),
]
operations = [
migrations.AddField(
model_name='contentimage',
name='source',
field=models.CharField(
choices=[
('upload', 'Upload'),
('google', 'Google'),
('wikipedia', 'Wikipedia'),
('url', 'URL'),
('immich', 'Immich'),
],
default='upload',
max_length=20,
),
),
migrations.AddField(
model_name='contentimage',
name='source_url',
field=models.URLField(blank=True, max_length=2048, null=True),
),
migrations.AddField(
model_name='contentimage',
name='coordinates',
field=django.contrib.gis.db.models.fields.PointField(
blank=True, null=True, srid=4326
),
),
migrations.RunPython(backfill_image_source, noop),
]