Posts

Showing posts from March, 2018

Mastering Django ORM Update Queries — From Basics to Pro Level

Updating data properly is just as important as selecting data. In this guide, you will learn how to update records correctly in Django ORM — from basic .save() usage to pro techniques like atomic updates, bulk updates, F expressions, and best practices! 📚 1. Basic Update Using .save() Fetch and modify a single object user = NewUser.objects.get(pk=1) user.email = 'newemail@example.com' user.save() ⚡ 2. Updating Specific Fields with .save(update_fields=[...]) user = NewUser.objects.get(pk=1) user.email = 'newemail@example.com' user.save(update_fields=['email']) 🎯 3. Updating Multiple Records at Once Using .update() NewUser.objects.filter(user_type=2).update(is_active=False) 🧠 4. .save() vs .update() — Key Differences Aspect .save() .update() Works on Single object QuerySet (multiple) Triggers signals? ✅ Yes ❌ No Auto-updates auto_now fields? ✅ Yes ❌ No Custom logic inside save() runs? ✅ Yes ❌ No Speed for bulk ❌ Slow ✅ Fast 🔥 5. Upda...

Regular Expression Fundamentals : Practical Examples

Image
Regular Expression Fundamentals : Practical Examples - LifeAdda Before getting into regular expressions, first needs to understand the data on we're planning to apply regular expressions. Below are few important data types : Characters a-z & A-Z Digits 0-9 Words letter, digit or underscore collection White-space white space is any character or series of characters that represent horizontal (Spacebar, Tab) or vertical space (Enter) in typography. Boundaries The word boundary is the position of word (letter, digit or underscore collection) Anchors ^ and $ called anchors Basic Meta-characters : * A line terminator is a one- or two-character sequence that marks the end of a line of the input character sequence. The following are recognized as line terminators: A newline (line feed) character ('\n') A carriage-return character followed immediately by a newline character ("\r\n") A standalone carriage-return character ('\r'...