diff --git a/src/products/models.py b/src/products/models.py index 08be5cc..232d08d 100644 --- a/src/products/models.py +++ b/src/products/models.py @@ -1,9 +1,12 @@ from django.db import models - +from django.urls import reverse # Create your models here. class Product(models.Model): title = models.CharField(max_length=120) # max_length = required description = models.TextField(blank=True, null=True) price = models.DecimalField(decimal_places=2, max_digits=10000) summary = models.TextField(blank=False, null=False) - featured = models.BooleanField(default=False) # null=True, default=True \ No newline at end of file + featured = models.BooleanField(default=False) # null=True, default=True + + def get_absolute_url(self): + return reverse("product-detail", kwargs={"id": self.id}) #f"/products/{self.id}/" \ No newline at end of file diff --git a/src/products/templates/products/product_list.html b/src/products/templates/products/product_list.html index 39d070c..7a0c768 100644 --- a/src/products/templates/products/product_list.html +++ b/src/products/templates/products/product_list.html @@ -5,7 +5,7 @@ {% for instance in object_list %} -

{{ instance.id }} - {{ instance.title }}

+

{{ instance.id }} - {{ instance.title }}

{% endfor %} diff --git a/src/trydjango/urls.py b/src/trydjango/urls.py index e6c0894..bd73ffd 100644 --- a/src/trydjango/urls.py +++ b/src/trydjango/urls.py @@ -28,21 +28,8 @@ urlpatterns = [ path('products/', product_list_view, name='product-list'), - - - - - - - - - - - - - - - path('products//', dynamic_lookup_view, name='product'), + path('prdocuts//', dynamic_lookup_view, name='product-detail'), + path('products//delete/', product_delete_view, name='product-delete'),