Django

College Event Registration Website

CampusConnect Introduction and Setup Configuring settings file for template, static and media files Setting up Tailwind Creating Custom User Model Creating Super User for CampusConnect Registering Custom User Model Search and Filter for User Model Serving Media Files During Development Categorizing Departments Linking Department with HOD Creating Abstract Model for Event Creating Model for Workshop Customizing Admin Page for Workshop Update in Model AbstractEvent Adding Instructor for Workshop Instructor Model Admin Page Adding Poster Field in Abstract Event Providing Access to HOD Access Update for HOD Restricting HOD Access to Particular Department AbstractEvent On Spot Registration Field Creating Workshop Object Creating and Linking Home Page Displaying Workshop on Home Page Styling Home Page Adding Workshop Detail Page Link Workshop Detail Page Workshop Detail Page Styling Workshop Instructor Details Workshop Detail Contact Contact Admin Page Many to Many Field for Contact Displaying Contact on Workshop Detail Page Adding Title for Workshop Detail Page Adding Gallery for Workshop Workshop Gallery Admin Page Displaying Gallery Images on Website Through Context Displaying Gallery Images on Website through template tags Authentication for users User Registration User Registration Submission Logout Functionality For User Login Functionality for User Model For Workshop Registration Workshop Registration Admin Page Register Workshop Function Register Button in Workshop Page Validations Before Workshop Registration Workshop Registration Closed Validaiton User Already Registered for Workshop Validation Workshop Registration Report From Admin Page Export using Library in Django Admin Extending Abstract Event for Hackathons

Delete a Note

The Create, Read and Update operations are performed on the Notes Model. Now its time to delete a note from the database.

A particular instance of a note can be deleted from the database using the delete method of the object. A function can be written in the notesapp\views.py file for the same as follows :

def note_delete(request, pk):
    note = Note.objects.get(pk=pk)
    note.delete()
    return redirect('home')

This function gets the instance using its primary key and then calls the delete method to remove it from the database.

A route for the above function can be created in the notesapp\urls.py file as follows :

path('note-delete/<int:pk>', views.note_delete, name='note_delete'),

And the corresponding link, should be updated in the home.html file as well.

<a href="{% url 'note_delete' note.pk %}" class="btn btn-danger">Delete</a>

Now, clicking on the delete button would remove that particular note from the database.

alt textThe first note, with title of Meeting Agenda has been removed from the database, by clicking the delete button.