-
Notifications
You must be signed in to change notification settings - Fork 834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution #889
base: master
Are you sure you want to change the base?
Solution #889
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,43 @@ class DriverListView(LoginRequiredMixin, generic.ListView): | |
class DriverDetailView(LoginRequiredMixin, generic.DetailView): | ||
model = Driver | ||
queryset = Driver.objects.all().prefetch_related("cars__manufacturer") | ||
|
||
|
||
class ManufacturerCreateView(LoginRequiredMixin, generic.CreateView): | ||
model = Manufacturer | ||
fields = "__all__" | ||
template_name = "taxi/manufacturer_form.html" | ||
success_url = "taxi/manufacturer_list" | ||
|
||
|
||
class ManufacturerUpdateView(LoginRequiredMixin, generic.UpdateView): | ||
model = Manufacturer | ||
fields = "__all__" | ||
template_name = "taxi/manufacturer_form.html" | ||
success_url = "taxi/manufacturer_list" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous comment, the |
||
|
||
|
||
class ManufacturerDeleteView(LoginRequiredMixin, generic.DeleteView): | ||
model = Manufacturer | ||
success_url = "taxi/manufacturer_list" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure |
||
template_name = "taxi/manufacturer_delete_confirmation.html" | ||
|
||
|
||
class CarCreateView(LoginRequiredMixin, generic.CreateView): | ||
model = Car | ||
fields = "__all__" | ||
template_name = "taxi/car_form.html" | ||
success_url = "taxi/car_list" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
|
||
class CarUpdateView(LoginRequiredMixin, generic.UpdateView): | ||
model = Car | ||
fields = "__all__" | ||
template_name = "taxi/car_form.html" | ||
success_url = "taxi/car_list" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
|
||
|
||
class CarDeleteView(LoginRequiredMixin, generic.DeleteView): | ||
model = Car | ||
success_url = "taxi/car_list" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure |
||
template_name = "taxi/car_delete_confirmation.html" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1>Deleting Car from the List</h1> | ||
<p><strong>WARNING!</strong> You're trying to delete a car: | ||
<strong>{{ car }}</strong> from the list.</p> | ||
<p>Are you sure want to delete this car? | ||
Press "Submit" button to confirm.</p> | ||
<form action="" method="post"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's important to include a CSRF token in forms to protect against CSRF attacks. Add |
||
<input type="submit" value="Submit" class="btn btn-danger"> | ||
</form> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,11 @@ <h1>Drivers</h1> | |
<li>{{ driver.username }} ({{ driver.first_name }} {{ driver.last_name }})</li> | ||
{% endfor %} | ||
</ul> | ||
<form action="{% url 'taxi:car-update' pk=car.id %}"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The form for updating the car should use the |
||
<input type="submit" value="UPDATE CAR" class="btn btn-info"> | ||
</form> | ||
<br> | ||
<form action="{% url 'taxi:car-delete' pk=car.id %}"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The form for deleting the car should use the |
||
<input type="submit" value="DELETE CAR" class="btn btn-danger"> | ||
</form> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% extends "base.html" %} | ||
{% load crispy_forms_filters %} | ||
{% block content %} | ||
<h1>{{ object|yesno:"Update,Create" }} a Car</h1> | ||
<form action="" method="post"> | ||
{% csrf_token %} | ||
{{ form|crispy }} | ||
<input type="submit" value="Submit" class="btn btn-info"> | ||
</form> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1>Deleting Manufacturer from the List</h1> | ||
<p><strong>WARNING!</strong> You're trying to delete a manufacturer: | ||
<strong>{{ manufacturer }}</strong> from the list.</p> | ||
<p>This causes a deleting related cars from the cars list too.</p> | ||
<p>Are you sure want to delete this manufacturer? | ||
Press "Submit" button to confirm.</p> | ||
<form action="" method="post"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include |
||
<input type="submit" value="Submit" class="btn btn-danger "> | ||
</form> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% extends "base.html" %} | ||
{% load crispy_forms_filters %} | ||
{% block content %} | ||
<h1>{{ object|yesno:"Update,Create" }} a Manufacturer</h1> | ||
<form action="" method="post"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include |
||
{{ form|crispy }} | ||
<input type="submit" value="Submit" class="btn btn-info"> | ||
</form> | ||
{% endblock %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add newline |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ <h1>Manufacturer List | |
<th>ID</th> | ||
<th>Name</th> | ||
<th>Country</th> | ||
<th>Update</th> | ||
<th>Delete</th> | ||
</tr> | ||
|
||
{% for manufacturer in manufacturer_list %} | ||
|
@@ -23,10 +25,23 @@ <h1>Manufacturer List | |
<td> | ||
{{ manufacturer.country }} | ||
</td> | ||
<td> | ||
<a href="{% url 'taxi:manufacturer-update' pk=manufacturer.id %}">Update</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a form with the |
||
</td> | ||
<td> | ||
<a | ||
href="{%url 'taxi:manufacturer-delete' pk=manufacturer.id %}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URL tag syntax is incorrect due to the lack of space between |
||
style="color: red;" | ||
>Delete</a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
|
||
<br> | ||
<form action="{% url 'taxi:manufacturer-create' %}"> | ||
<input type="submit" value="Add" class="btn btn-success"> | ||
</form> | ||
<br> | ||
{% else %} | ||
<p>There are no manufacturers in the service.</p> | ||
{% endif %} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
success_url
should be a URL pattern name, not a string representing a path. Consider using Django'sreverse_lazy
to reference the URL pattern name, likereverse_lazy('manufacturer-list')
.