Compare commits
No commits in common. "6ef959d10bb4d07957ea4f379949b00c170eb377" and "ec308a7428fe22af1885f7c924c188a91558e702" have entirely different histories.
6ef959d10b
...
ec308a7428
@ -1,8 +1,9 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
|
||||
from .models import Explorer, Place
|
||||
from .models import Explorer
|
||||
|
||||
class ExplorerCreationForm(UserCreationForm):
|
||||
|
||||
class Meta:
|
||||
model = Explorer
|
||||
fields = ('username', 'email')
|
||||
@ -12,9 +13,3 @@ class ExplorerChangeForm(UserChangeForm):
|
||||
class Meta:
|
||||
model = Explorer
|
||||
fields = ('username', 'email')
|
||||
|
||||
class PlaceForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Place
|
||||
fields = '__all__'
|
||||
exclude = ['submitted_by']
|
||||
|
@ -1,20 +0,0 @@
|
||||
# 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),
|
||||
),
|
||||
]
|
@ -1,20 +0,0 @@
|
||||
# Generated by Django 3.0.8 on 2020-07-29 18:22
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('lostplaces_app', '0002_place_submitted_by'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='place',
|
||||
name='submitted_by',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='places', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
@ -18,7 +18,6 @@ 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()
|
||||
|
@ -1,15 +0,0 @@
|
||||
{% extends 'global.html'%}
|
||||
{% load static %}
|
||||
|
||||
# {% block title %}Place erstellen{% endblock %}
|
||||
|
||||
{% block maincontent %}
|
||||
|
||||
<h2>Place erstellen</h2>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit">Abschicken</button>
|
||||
</form>
|
||||
|
||||
{% endblock maincontent %}
|
@ -1,10 +1,9 @@
|
||||
from django.urls import path
|
||||
from .views import hello_world, place_detail_view, place_list_view, SignUpView, PlaceEditView
|
||||
from .views import hello_world, place_detail_view, place_list_view, SignUpView
|
||||
|
||||
urlpatterns = [
|
||||
path('hello_world/', hello_world), # You know what this is :P
|
||||
path('signup/', SignUpView.as_view(), name='signup'),
|
||||
path('place/<int:pk>/', place_detail_view, name='place_detail'),
|
||||
path('place/create/', PlaceEditView.as_view(), name='place_create'),
|
||||
path('place/', place_list_view)
|
||||
path('places/', place_list_view)
|
||||
]
|
@ -1,9 +1,8 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.views import View
|
||||
|
||||
from .forms import ExplorerCreationForm, PlaceForm
|
||||
from .forms import ExplorerCreationForm
|
||||
from .models import Place
|
||||
|
||||
# Create your views here.
|
||||
@ -21,18 +20,3 @@ def place_detail_view(request, pk):
|
||||
|
||||
def hello_world(request):
|
||||
return render(request, 'hello_world.html', {'text':'Hello World!'})
|
||||
|
||||
class PlaceEditView(View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
place_form = PlaceForm()
|
||||
return render(request, 'create_place.html', {'form':place_form})
|
||||
def post(self, request, *args, **kwargs):
|
||||
place_form = PlaceForm(request.POST)
|
||||
if place_form.is_valid() == True:
|
||||
instance = place_form.save(commit=False)
|
||||
# Save logged in user as "submitted_by"
|
||||
instance.submitted_by = request.user
|
||||
instance.save()
|
||||
return redirect(reverse_lazy('place_detail', kwargs={'pk':instance.pk}))
|
||||
else:
|
||||
return render(request, 'create_place.html', {'form':place_form})
|
||||
|
Loading…
Reference in New Issue
Block a user