This commit is contained in:
Flatlogic Bot 2025-10-31 17:00:04 +00:00
parent ec720dbd4b
commit 235f0a8a83
7 changed files with 59 additions and 1 deletions

View File

@ -0,0 +1,13 @@
{% extends 'base.html' %}
{% block content %}
<div class="container mt-5">
<h2>Delete Property</h2>
<p>Are you sure you want to delete "{{ property.title }}"?</p>
<form method="post">
{% csrf_token %}
<button type="submit" class="btn btn-danger">Confirm Delete</button>
<a href="{% url 'property_detail' property.id %}" class="btn btn-secondary">Cancel</a>
</form>
</div>
{% endblock %}

View File

@ -20,6 +20,11 @@
<div class="card-body">
<h5 class="card-title">Book this property</h5>
<a href="{% url 'booking_create' property.id %}" class="btn btn-primary">Book Now</a>
{% if user.is_authenticated and user == property.owner %}
<hr>
<a href="{% url 'property_update' property.id %}" class="btn btn-secondary">Edit Property</a>
<a href="{% url 'property_delete' property.id %}" class="btn btn-danger mt-2">Delete Property</a>
{% endif %}
</div>
</div>
</div>

View File

@ -0,0 +1,12 @@
{% extends 'base.html' %}
{% block content %}
<div class="container mt-5">
<h2>Edit Property</h2>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="btn btn-primary">Save Changes</button>
</form>
</div>
{% endblock %}

View File

@ -1,6 +1,6 @@
from django.urls import path
from .views import index, signup_view, login_view, logout_view, property_detail, property_create, booking_create, profile, about, contact, faq
from .views import index, signup_view, login_view, logout_view, property_detail, property_create, booking_create, profile, about, contact, faq, property_update, property_delete
urlpatterns = [
path("", index, name="index"),
@ -14,4 +14,6 @@ urlpatterns = [
path("about/", about, name="about"),
path("contact/", contact, name="contact"),
path("faq/", faq, name="faq"),
path("property/<int:property_id>/update/", property_update, name="property_update"),
path("property/<int:property_id>/delete/", property_delete, name="property_delete"),
]

View File

@ -84,3 +84,29 @@ def contact(request):
def faq(request):
return render(request, 'core/faq.html')
@login_required
def property_update(request, property_id):
property = get_object_or_404(Property, pk=property_id)
if property.owner != request.user:
return redirect('property_detail', property_id=property.id)
if request.method == 'POST':
form = PropertyForm(request.POST, request.FILES, instance=property)
if form.is_valid():
form.save()
return redirect('property_detail', property_id=property.id)
else:
form = PropertyForm(instance=property)
return render(request, 'core/property_update.html', {'form': form, 'property': property})
@login_required
def property_delete(request, property_id):
property = get_object_or_404(Property, pk=property_id)
if property.owner != request.user:
return redirect('property_detail', property_id=property.id)
if request.method == 'POST':
property.delete()
return redirect('index')
return render(request, 'core/property_delete.html', {'property': property})