-
Notifications
You must be signed in to change notification settings - Fork 886
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 #904
base: master
Are you sure you want to change the base?
solution #904
Changes from all commits
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from django.contrib.auth.decorators import login_required | ||
from django.shortcuts import render | ||
from django.urls import reverse_lazy | ||
from django.views import generic | ||
from django.contrib.auth.mixins import LoginRequiredMixin | ||
|
||
|
@@ -34,6 +35,26 @@ class ManufacturerListView(LoginRequiredMixin, generic.ListView): | |
paginate_by = 5 | ||
|
||
|
||
class ManufacturerCreateView(LoginRequiredMixin, generic.CreateView): | ||
model = Manufacturer | ||
fields = "__all__" | ||
success_url = reverse_lazy("taxi:manufacturer-list") | ||
template_name = "taxi/manufacturer_form.html" | ||
|
||
|
||
class ManufacturerUpdateView(LoginRequiredMixin, generic.UpdateView): | ||
model = Manufacturer | ||
fields = "__all__" | ||
success_url = reverse_lazy("taxi:manufacturer-list") | ||
template_name = "taxi/manufacturer_form.html" | ||
|
||
|
||
class ManufacturerDeleteView(LoginRequiredMixin, generic.DeleteView): | ||
model = Manufacturer | ||
success_url = reverse_lazy("taxi:manufacturer-list") | ||
template_name = "taxi/manufacturer_delete.html" | ||
|
||
|
||
class CarListView(LoginRequiredMixin, generic.ListView): | ||
model = Car | ||
paginate_by = 5 | ||
|
@@ -44,6 +65,26 @@ class CarDetailView(LoginRequiredMixin, generic.DetailView): | |
model = Car | ||
|
||
|
||
class CarCreateView(LoginRequiredMixin, generic.CreateView): | ||
model = Car | ||
fields = "__all__" | ||
success_url = reverse_lazy("taxi:car-list") | ||
template_name = "taxi/car_form.html" | ||
|
||
|
||
class CarUpdateView(LoginRequiredMixin, generic.UpdateView): | ||
model = Car | ||
fields = "__all__" | ||
success_url = reverse_lazy("taxi:car-list") | ||
template_name = "taxi/car_form.html" | ||
|
||
|
||
class CarDeleteView(LoginRequiredMixin, generic.DeleteView): | ||
model = Manufacturer | ||
Comment on lines
+82
to
+83
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 |
||
success_url = reverse_lazy("taxi:car-list") | ||
template_name = "taxi/car_delete.html" | ||
|
||
|
||
class DriverListView(LoginRequiredMixin, generic.ListView): | ||
model = Driver | ||
paginate_by = 5 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% extends "base.html" %} | ||
{% block content %} | ||
<h1>Delete car:</h1> | ||
<p>Are you sure you want to delete the car: {{ car }}?</p> | ||
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 template uses |
||
<p><i>All data related to this car will be also deleted!</i></p> | ||
<form action="" method="post"> | ||
{% csrf_token %} | ||
<input type="submit" value="Yes, delete" class="btn btn-danger"> | ||
</form> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,6 @@ <h1>Drivers</h1> | |
<li>{{ driver.username }} ({{ driver.first_name }} {{ driver.last_name }})</li> | ||
{% endfor %} | ||
</ul> | ||
<a href="./update/" class="btn btn-primary">Update</a> | ||
<a href="./delete/" class="btn btn-primary">Delete</a> | ||
Comment on lines
+12
to
+13
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. Using relative URLs like |
||
{% 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>{{ objects|yesno:"Update,Create" }} car:</h1> | ||
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 use of 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 use of |
||
<form action="" method="post" novalidate> | ||
{% csrf_token %} | ||
{{ form|crispy }} | ||
<input class="btn btn-primary" type="submit" value="Submit"> | ||
</form> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ <h1>Car list</h1> | |
{% else %} | ||
<p>There are no cars in taxi</p> | ||
{% endif %} | ||
<a href="./create/" class="m-md-2 btn btn-primary">Add new car</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. Using a relative URL like |
||
|
||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% extends "base.html" %} | ||
{% block content %} | ||
<h1>Delete manufacturer:</h1> | ||
<p>Are you sure you want to delete the manufacturer: {{ manufacturer }}?</p> | ||
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 template uses |
||
<p><i>All cars with this manufacturer will be also deleted!</i></p> | ||
<form action="" method="post"> | ||
{% csrf_token %} | ||
<input type="submit" value="Yes, delete" 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>{{ objects|yesno:"Update,Create" }} manufacturer:</h1> | ||
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 use of 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 use of |
||
<form action="" method="post" novalidate> | ||
{% csrf_token %} | ||
{{ form|crispy }} | ||
<input class="btn btn-primary" type="submit" value="Submit"> | ||
</form> | ||
{% endblock %} |
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,11 +25,18 @@ <h1>Manufacturer List | |
<td> | ||
{{ manufacturer.country }} | ||
</td> | ||
<td> | ||
<a href="{{ manufacturer.id }}/update/" class="btn btn-primary">+</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. The URL for the update link is hardcoded as 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. Using a relative URL like |
||
</td> | ||
<td> | ||
<a href="{{ manufacturer.id }}/delete/" class="btn btn-danger">-</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. The URL for the delete link is hardcoded as 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. Using a relative URL like |
||
</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
|
||
{% else %} | ||
<p>There are no manufacturers in the service.</p> | ||
{% endif %} | ||
<a href="./create/" class="m-md-2 btn btn-primary">Add new manufacturer</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. Using a relative URL like |
||
{% endblock %} |
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
CarDeleteView
should use theCar
model instead of theManufacturer
model. Ensure that the model is correctly specified to delete car instances.