diff --git a/core/__pycache__/urls.cpython-311.pyc b/core/__pycache__/urls.cpython-311.pyc index 17981d3..69352b2 100644 Binary files a/core/__pycache__/urls.cpython-311.pyc and b/core/__pycache__/urls.cpython-311.pyc differ diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index 5eca40a..b92a74a 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/templates/core/property_delete.html b/core/templates/core/property_delete.html new file mode 100644 index 0000000..f9db83a --- /dev/null +++ b/core/templates/core/property_delete.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block content %} +
+

Delete Property

+

Are you sure you want to delete "{{ property.title }}"?

+
+ {% csrf_token %} + + Cancel +
+
+{% endblock %} diff --git a/core/templates/core/property_detail.html b/core/templates/core/property_detail.html index cd13baa..e8722a5 100644 --- a/core/templates/core/property_detail.html +++ b/core/templates/core/property_detail.html @@ -20,6 +20,11 @@
Book this property
Book Now + {% if user.is_authenticated and user == property.owner %} +
+ Edit Property + Delete Property + {% endif %}
diff --git a/core/templates/core/property_update.html b/core/templates/core/property_update.html new file mode 100644 index 0000000..ef95438 --- /dev/null +++ b/core/templates/core/property_update.html @@ -0,0 +1,12 @@ +{% extends 'base.html' %} + +{% block content %} +
+

Edit Property

+
+ {% csrf_token %} + {{ form.as_p }} + +
+
+{% endblock %} diff --git a/core/urls.py b/core/urls.py index 1a1a32e..5827b7a 100644 --- a/core/urls.py +++ b/core/urls.py @@ -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//update/", property_update, name="property_update"), + path("property//delete/", property_delete, name="property_delete"), ] diff --git a/core/views.py b/core/views.py index 3313453..1c600e8 100644 --- a/core/views.py +++ b/core/views.py @@ -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})