Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

solution #904

wants to merge 2 commits into from

Conversation

Codoeh
Copy link

@Codoeh Codoeh commented Jan 12, 2025

No description provided.

@Codoeh
Copy link
Author

Codoeh commented Jan 12, 2025

car_create
car_delete
car_detail
car_list

manufacturer_create
manufacturer_delete
manufacturer_list
manufacturer_update

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your hard work on this project! While you've made great progress, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Incorrect Model Usage in Views:

    • The CarUpdateView and CarDeleteView are currently set to use the Manufacturer model instead of the Car model. This is a critical issue as it impacts the core functionality of updating and deleting car instances. Please correct the model to ensure these views work as intended.
  2. Template URL Generation:

    • In the templates, URLs for update and delete actions are hardcoded. It's recommended to use the {% url %} template tag to dynamically generate URLs. This ensures consistency with the URL patterns defined in urls.py and improves maintainability.
  3. Template Logic for Form Headings:

    • The logic for determining whether a form is for updating or creating an object seems incorrect. Ensure that the context variable object is correctly used in the template to reflect the correct action.

These changes are necessary to ensure the application functions correctly and aligns with best practices. Once these issues are resolved, we can proceed with the approval. Keep up the great work, and don't hesitate to reach out if you need any assistance! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

taxi/views.py Outdated


class CarUpdateView(LoginRequiredMixin, generic.UpdateView):
model = Manufacturer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CarUpdateView should use the Car model instead of the Manufacturer model. Ensure that the model is correctly specified to update car instances.



class CarDeleteView(LoginRequiredMixin, generic.DeleteView):
model = Manufacturer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CarDeleteView should use the Car model instead of the Manufacturer model. Ensure that the model is correctly specified to delete car instances.

{% extends "base.html" %}
{% load crispy_forms_filters %}
{% block content %}
<h1>{{ objects|yesno:"Update,Create" }} car:</h1>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of objects|yesno:"Update,Create" seems incorrect. It should likely be object|yesno:"Update,Create" to determine whether the form is for updating or creating based on the presence of an object instance. Ensure that the context variable object is correctly passed to the template.

{% extends "base.html" %}
{% load crispy_forms_filters %}
{% block content %}
<h1>{{ objects|yesno:"Update,Create" }} manufacturer:</h1>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of objects|yesno:"Update,Create" seems incorrect. It should likely be object|yesno:"Update,Create" to determine whether the form is for updating or creating based on the presence of an object instance. Ensure that the context variable object is correctly passed to the template.

@@ -23,11 +25,18 @@ <h1>Manufacturer List
<td>
{{ manufacturer.country }}
</td>
<td>
<a href="{{ manufacturer.id }}/update/" class="btn btn-primary">+</a>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL for the update link is hardcoded as {{ manufacturer.id }}/update/. It would be better to use the {% url %} template tag to generate the URL dynamically, ensuring it aligns with the URL patterns defined in urls.py. For example: {% url 'taxi:manufacturer-update' pk=manufacturer.id %}.

<a href="{{ manufacturer.id }}/update/" class="btn btn-primary">+</a>
</td>
<td>
<a href="{{ manufacturer.id }}/delete/" class="btn btn-danger">-</a>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL for the delete link is hardcoded as {{ manufacturer.id }}/delete/. It would be better to use the {% url %} template tag to generate the URL dynamically, ensuring it aligns with the URL patterns defined in urls.py. For example: {% url 'taxi:manufacturer-delete' pk=manufacturer.id %}.

@Codoeh
Copy link
Author

Codoeh commented Jan 12, 2025

Uploading fixed_car_update.PNG…

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Great job on your progress so far! 🎉 While the Pull Request is approved to help you move forward with your learning, there are several critical issues that need attention to ensure your application functions correctly:

  1. Incorrect Model Usage in Views:

    • The CarDeleteView is currently using the Manufacturer model instead of the Car model. This needs to be corrected to ensure the delete functionality works as intended.
  2. Template URL Generation:

    • Many templates use relative URLs, which can lead to issues if the URL structure changes. It's recommended to use the {% url %} template tag to dynamically generate URLs based on the named URL patterns defined in urls.py. This applies to links for creating, updating, and deleting both cars and manufacturers.
  3. Template Logic for Form Headings:

    • The logic for determining whether a form is for updating or creating an object is incorrect in car_form.html and manufacturer_form.html. The context variable object should be used instead of objects to reflect the correct action.
  4. Context Variables in Templates:

    • Ensure that the correct context variables are passed to templates. For example, {{ car }} and {{ manufacturer }} should be correctly passed from the views to display the respective information.

These changes are crucial for the functionality and maintainability of your code. Please review the comments and make the necessary adjustments to improve your code. Keep up the good work and continue learning from these experiences! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines +82 to +83
class CarDeleteView(LoginRequiredMixin, generic.DeleteView):
model = Manufacturer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CarDeleteView is incorrectly using the Manufacturer model. It should be using the Car model to delete car instances. Please change model = Manufacturer to model = Car.

{% extends "base.html" %}
{% block content %}
<h1>Delete car:</h1>
<p>Are you sure you want to delete the car: {{ car }}?</p>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The template uses {{ car }} to display the car's information. Ensure that the context variable car is correctly passed from the view to this template. If the context variable is named differently, update it accordingly.

Comment on lines +12 to +13
<a href="./update/" class="btn btn-primary">Update</a>
<a href="./delete/" class="btn btn-primary">Delete</a>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using relative URLs like ./update/ and ./delete/ can lead to issues if the URL structure changes. It's recommended to use the {% url %} template tag to dynamically generate these URLs based on the named URL patterns defined in urls.py. For example, {% url 'taxi:car-update' car.id %} for the update link.

{% extends "base.html" %}
{% load crispy_forms_filters %}
{% block content %}
<h1>{{ objects|yesno:"Update,Create" }} car:</h1>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of {{ objects|yesno:"Update,Create" }} is incorrect because objects is not a standard context variable for determining form actions. Typically, you would check if the form instance has an id or use a context variable like is_update to decide between 'Update' and 'Create'. Ensure the correct context variable is used here.

@@ -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>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a relative URL like ./create/ for the 'Add new car' link can lead to issues if the URL structure changes. It's recommended to use the {% url %} template tag to dynamically generate this URL based on the named URL pattern defined in urls.py. For example, {% url 'taxi:car-create' %}.

{% extends "base.html" %}
{% block content %}
<h1>Delete manufacturer:</h1>
<p>Are you sure you want to delete the manufacturer: {{ manufacturer }}?</p>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The template uses {{ manufacturer }} to display the manufacturer's information. Ensure that the context variable manufacturer is correctly passed from the view to this template. If the context variable is named differently, update it accordingly.

{% extends "base.html" %}
{% load crispy_forms_filters %}
{% block content %}
<h1>{{ objects|yesno:"Update,Create" }} manufacturer:</h1>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of {{ objects|yesno:"Update,Create" }} is incorrect because objects is not a standard context variable for determining form actions. Typically, you would check if the form instance has an id or use a context variable like is_update to decide between 'Update' and 'Create'. Ensure the correct context variable is used here.

@@ -23,11 +25,18 @@ <h1>Manufacturer List
<td>
{{ manufacturer.country }}
</td>
<td>
<a href="{{ manufacturer.id }}/update/" class="btn btn-primary">+</a>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a relative URL like {{ manufacturer.id }}/update/ can lead to issues if the URL structure changes. It's recommended to use the {% url %} template tag to dynamically generate this URL based on the named URL pattern defined in urls.py. For example, {% url 'taxi:manufacturer-update' manufacturer.id %}.

<a href="{{ manufacturer.id }}/update/" class="btn btn-primary">+</a>
</td>
<td>
<a href="{{ manufacturer.id }}/delete/" class="btn btn-danger">-</a>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a relative URL like {{ manufacturer.id }}/delete/ can lead to issues if the URL structure changes. It's recommended to use the {% url %} template tag to dynamically generate this URL based on the named URL pattern defined in urls.py. For example, {% url 'taxi:manufacturer-delete' manufacturer.id %}.

</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>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a relative URL like ./create/ for the 'Add new manufacturer' link can lead to issues if the URL structure changes. It's recommended to use the {% url %} template tag to dynamically generate this URL based on the named URL pattern defined in urls.py. For example, {% url 'taxi:manufacturer-create' %}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants