Enjoy these free Code Nuggets?
Your support helps us create more high-quality content and unlocks exclusive premium nuggets via a personal activation link.
Support Our Work & Get Exclusive AccessLearn to code with AI, not just about it.
Beyond free snippets, we run hands-on training in AI-assisted coding — teaching developers, teams and beginners how to build real software faster using modern AI tools. You bring the ideas; we show you how to ship them with an AI pair-programmer at your side.
- ✔ Prompting & pairing with AI coding assistants to write, debug and refactor real code
- ✔ Turning plain-English ideas into working apps, scripts and automations
- ✔ Reviewing AI output safely — spotting bugs, security gaps and hallucinations
- ✔ Live cohorts, team workshops and 1-on-1 mentoring — remote or on-site in Kenya
# You describe it…
"Build me a booking form that emails the client."
# …the AI drafts it…
▸ generating form + mailer…
â–¸ 24 lines written, 0 errors
# …and we teach you to lead it.
✱ You stay the engineer. AI is the tool.
Django nuggets
3 nuggets found
Thinner Views with Django Class-Based Views (Premium)
Most list and detail pages follow the same pattern: fetch a queryset, paginate, render a template. Django's generic class-based views hand you that for free, so a full listing page...
from django.views.generic import ListView, DetailView
from .models import Article
class ArticleList(ListView):
model = Article
paginate_by = 10
context_object_name = "articles"
def get_queryset(self):
qs = super().get_queryset().filter(is_published=True)
if q := sel...
Encapsulating Queries in a Custom Django Manager (Premium)
Sprinkling filter(is_published=True) across your codebase invites bugs. A custom manager gives your model expressive, reusable query methods like Article.objects.published().
from django.db import models
from django.utils import timezone
class ArticleQuerySet(models.QuerySet):
def published(self):
return self.filter(is_published=True, published_at__lte=timezone.now())
def by_author(self, user):
return self.filter(author=user)
class Article(mode...
Reacting to Model Events with Django Signals (Premium)
Need a profile created automatically whenever a user signs up? Signals let you run code in response to model events without cluttering your save logic.
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth import get_user_model
from .models import Profile
User = get_user_model()
@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
if created:...