diff --git a/.gitignore b/.gitignore index 245d50f..5188462 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ local_settings.py db.sqlite3 db.sqlite3-journal media +uploads # If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ # in your Git repository. Update and uncomment the following line accordingly. diff --git a/source/lostplaces/lostplaces/urls.py b/source/lostplaces/lostplaces/urls.py index c76d05e..d06e2ae 100644 --- a/source/lostplaces/lostplaces/urls.py +++ b/source/lostplaces/lostplaces/urls.py @@ -14,9 +14,11 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path, include +from django.conf import settings +from django.conf.urls.static import static +from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('', include('lostplaces_app.urls')), -] +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/source/lostplaces/lostplaces_app/admin.py b/source/lostplaces/lostplaces_app/admin.py index 5adc602..3b933d6 100644 --- a/source/lostplaces/lostplaces_app/admin.py +++ b/source/lostplaces/lostplaces_app/admin.py @@ -4,3 +4,4 @@ from .models import * # Register your models here. admin.site.register(Place) +admin.site.register(PlaceImage) \ No newline at end of file diff --git a/source/lostplaces/lostplaces_app/migrations/0002_placeimage.py b/source/lostplaces/lostplaces_app/migrations/0002_placeimage.py new file mode 100644 index 0000000..dac2ddd --- /dev/null +++ b/source/lostplaces/lostplaces_app/migrations/0002_placeimage.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.8 on 2020-07-27 17:58 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces_app', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='PlaceImage', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('filename', models.ImageField(max_length=50, upload_to='places/%Y/%m/')), + ('description', models.TextField()), + ('place', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='images', to='lostplaces_app.Place')), + ], + ), + ] diff --git a/source/lostplaces/lostplaces_app/migrations/0003_auto_20200727_1801.py b/source/lostplaces/lostplaces_app/migrations/0003_auto_20200727_1801.py new file mode 100644 index 0000000..0373521 --- /dev/null +++ b/source/lostplaces/lostplaces_app/migrations/0003_auto_20200727_1801.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.8 on 2020-07-27 18:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces_app', '0002_placeimage'), + ] + + operations = [ + migrations.AlterField( + model_name='placeimage', + name='description', + field=models.TextField(null=True), + ), + ] diff --git a/source/lostplaces/lostplaces_app/migrations/0004_auto_20200727_1803.py b/source/lostplaces/lostplaces_app/migrations/0004_auto_20200727_1803.py new file mode 100644 index 0000000..8b9c753 --- /dev/null +++ b/source/lostplaces/lostplaces_app/migrations/0004_auto_20200727_1803.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.8 on 2020-07-27 18:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces_app', '0003_auto_20200727_1801'), + ] + + operations = [ + migrations.AlterField( + model_name='placeimage', + name='description', + field=models.TextField(blank=True, default=''), + preserve_default=False, + ), + ] diff --git a/source/lostplaces/lostplaces_app/models.py b/source/lostplaces/lostplaces_app/models.py index fccdaea..3f3ece8 100644 --- a/source/lostplaces/lostplaces_app/models.py +++ b/source/lostplaces/lostplaces_app/models.py @@ -8,4 +8,14 @@ class Place (models.Model): latitude = models.FloatField() longitude = models.FloatField() description = models.TextField() - \ No newline at end of file + + def __str__(self): + return self.name + +class PlaceImage (models.Model): + filename = models.ImageField(upload_to='places/%Y/%m/', max_length=50) + place = models.ForeignKey(Place, on_delete=models.CASCADE, related_name='images') + description = models.TextField(blank=True) + + def __str__(self): + return ' '.join([self.place.name, str(self.pk)])