Django Query Filtering and User Profile Implementation

Day 130-131 📘 Python Full Stack Journey – Django Query Filtering 🔍 Today I explored how to filter data in Django using QuerySets, which is a powerful way to retrieve specific records from the database. 🚀 🎯 What I learned today: 🔎 Django Filter Queries Used different filtering techniques on the Employee model: startswith → fetch records where a field starts with a value endswith → fetch records where a field ends with a value icontains → case-insensitive search within a field Example: Employee.objects.filter(fullname__startswith='A') 📊 Displaying Filtered Data Passed multiple filtered datasets from views → template Used Django template loops to display results dynamically ⚙️ Multiple Filters in One View Combined multiple queries in a single function Even filtered data from different models in one page 💡 This makes it easy to build features like search, filtering, and categorization in web applications. Django User Profile (One-to-One Relationship) Today I implemented a User Profile system in Django using a One-to-One relationship, taking a big step toward building personalized user experiences. 👤 One-to-One Relationship Created a Profile model linked to Django’s built-in User model Ensured one user → one profile using: user = models.OneToOneField(User, on_delete=models.CASCADE) Understood how Django handles relationships like one-to-one, one-to-many, and many-to-many 🗄️ Profile Model Fields Added fields like: Bio Location Birth date Profile image Used: blank=True and null=True for optional fields ImageField for uploading profile pictures 🌐 Profile Display & Editing Displayed logged-in user details using: {{ request.user.username }} Created a profile page and an edit form page Used get_or_create() to automatically create a profile if it doesn’t exist 🔐 Access Control Used @login_required decorator to restrict access to logged-in users only 📸 Handling File Uploads Used enctype="multipart/form-data" for image uploads Displayed uploaded images dynamically in templates This session helped me understand how to build user-specific features and profiles, along with how Django makes data retrieval flexible and efficient—both of which are essential for real-world applications like social platforms, search systems, and dashboards. Excited to keep building more personalized and dynamic applications while exploring advanced queries next! 💻✨ #Django #Python #FullStackDevelopment #WebDevelopment #Backend #BackendDevelopment #Database #QuerySets #UserProfile #CodingJourney #LearningToCode #Upskilling #ContinuousLearning

  • graphical user interface, text, application, email

To view or add a comment, sign in

Explore content categories