Removed ability to add other caves entrances to a cave.

This commit is contained in:
Martin Green 2023-07-05 18:22:08 +01:00
parent a0fcb78e95
commit 63599cb27a

View File

@ -372,8 +372,8 @@ def edit_cave(request, path="", slug=None):
cave = Cave() cave = Cave()
if request.POST: if request.POST:
form = CaveForm(request.POST, instance=cave) form = CaveForm(request.POST, instance=cave)
ceFormSet = CaveAndEntranceFormSet(request.POST) #ceFormSet = CaveAndEntranceFormSet(request.POST)
if form.is_valid() and ceFormSet.is_valid(): if form.is_valid(): # and ceFormSet.is_valid():
# print(f'! POST is valid. {cave}') # print(f'! POST is valid. {cave}')
cave = form.save(commit=False) cave = form.save(commit=False)
if not cave.filename: if not cave.filename:
@ -385,10 +385,10 @@ def edit_cave(request, path="", slug=None):
if slug is None: if slug is None:
cs = CaveSlug(cave=cave, slug=cave.reference(), primary=True) cs = CaveSlug(cave=cave, slug=cave.reference(), primary=True)
cs.save() cs.save()
ceinsts = ceFormSet.save(commit=False) #ceinsts = ceFormSet.save(commit=False)
for ceinst in ceinsts: #for ceinst in ceinsts:
ceinst.cave = cave # ceinst.cave = cave
ceinst.save() # ceinst.save()
try: try:
cave_file = cave.file_output() cave_file = cave.file_output()
write_and_commit([cave_file], f"Online edit of cave {cave}") write_and_commit([cave_file], f"Online edit of cave {cave}")
@ -407,13 +407,14 @@ def edit_cave(request, path="", slug=None):
else: else:
if slug is not None: if slug is not None:
# re-read cave data from file. # re-read cave data from file.
read_cave(cave.filename, cave=cave) if cave.filename:
read_cave(cave.filename, cave=cave)
form = CaveForm(instance=cave, initial={'cave_slug': cave.slug()}) form = CaveForm(instance=cave, initial={'cave_slug': cave.slug()})
ceFormSet = CaveAndEntranceFormSet(queryset=cave.caveandentrance_set.all()) #ceFormSet = CaveAndEntranceFormSet(queryset=cave.caveandentrance_set.all())
else: else:
form = CaveForm() form = CaveForm()
ceFormSet = CaveAndEntranceFormSet(queryset=CaveAndEntrance.objects.none()) #ceFormSet = CaveAndEntranceFormSet(queryset=CaveAndEntrance.objects.none())
return render( return render(
request, request,
@ -422,7 +423,7 @@ def edit_cave(request, path="", slug=None):
"form": form, "form": form,
"cave": cave, "cave": cave,
"message": message, "message": message,
"caveAndEntranceFormSet": ceFormSet, #"caveAndEntranceFormSet": ceFormSet,
"path": path + "/", "path": path + "/",
}, },
) )