diff --git a/lostplaces/lostplaces_app/forms.py b/lostplaces/lostplaces_app/forms.py index fc99edc..734e77d 100644 --- a/lostplaces/lostplaces_app/forms.py +++ b/lostplaces/lostplaces_app/forms.py @@ -1,9 +1,8 @@ from django import forms from django.contrib.auth.forms import UserCreationForm, UserChangeForm -from .models import Explorer +from .models import Explorer, Place class ExplorerCreationForm(UserCreationForm): - class Meta: model = Explorer fields = ('username', 'email') @@ -13,3 +12,9 @@ class ExplorerChangeForm(UserChangeForm): class Meta: model = Explorer fields = ('username', 'email') + +class PlaceForm(forms.ModelForm): + class Meta: + model = Place + fields = '__all__' + exclude = ['submitted_by'] diff --git a/lostplaces/lostplaces_app/migrations/0002_place_submitted_by.py b/lostplaces/lostplaces_app/migrations/0002_place_submitted_by.py new file mode 100644 index 0000000..8fc80ff --- /dev/null +++ b/lostplaces/lostplaces_app/migrations/0002_place_submitted_by.py @@ -0,0 +1,20 @@ +# Generated by Django 3.0.8 on 2020-07-29 16:29 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces_app', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='place', + name='submitted_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/lostplaces/lostplaces_app/models.py b/lostplaces/lostplaces_app/models.py index 270f12f..42d3bae 100644 --- a/lostplaces/lostplaces_app/models.py +++ b/lostplaces/lostplaces_app/models.py @@ -18,6 +18,7 @@ class Explorer(AbstractUser): # Place defines a lost place (location, name, description etc.). class Place (models.Model): name = models.CharField(max_length=50) + submitted_by = models.ForeignKey(Explorer, on_delete=models.SET_NULL, null=True, blank=True, related_name='places') location = models.CharField(max_length=50) latitude = models.FloatField() longitude = models.FloatField() diff --git a/lostplaces/lostplaces_app/templates/create_place.html b/lostplaces/lostplaces_app/templates/create_place.html new file mode 100644 index 0000000..dab22be --- /dev/null +++ b/lostplaces/lostplaces_app/templates/create_place.html @@ -0,0 +1,15 @@ +{% extends 'global.html'%} +{% load static %} + +# {% block title %}Place erstellen{% endblock %} + +{% block maincontent %} + +