Today’s mission was simple — delete items from the frontend instead of logging into the admin panel every time.
Sounds simple, right? Well… not exactly 😅
⚙️ Starting with views.py
Created a dedicated delete function to access and remove a specific item.
This led me to learn about primary keys (pk) — Django’s way of identifying each object in the database.
Instead of just request, I passed the id as an argument to the function so I could access and delete that particular item.
And here’s something I felt really proud of 👇
When I didn’t see the expected output with render, I instantly switched to redirect — something I learned the hard way a few days ago!
That’s when I realized — I’m actually retaining concepts now 💪
💬 Success Message
After deleting an item, I added a Django success message —
“Item deleted successfully!”
One day’s concept turning useful in another day’s task — small, but meaningful progress!
🧩 URLs & Primary Keys
Initially, I wasn’t sure what to pass in the delete URL.
But after exploring the migrations folder, I noticed Django automatically assigns an id to every entry.
That realization clicked — migrations are not just about database setup, they’re about structure and consistency.
🧠 Template Update
Finally, updated home.html with a delete link:
<a href="{% url 'delete' item.id %}">Delete</a>
Simple tweak, but powerful once you see it working!
🎨 Next Curiosity:
How can I remove the blue underline (hyperlink style) from the tag and make my Delete button look cool?
Any CSS or Bootstrap tricks you’d recommend?
Also, how was your first experience working with primary keys and accessing specific items in Django?
Would love to hear how you approached it! 🙌
Top comments (0)