Grokking Django
Vote

0% completed

​

Writing Clean and Reusable Code in Django

Two views on the blog both show published articles. One writes the filter out in full, and the other calls a single method:

# Written out in each view Article.objects.filter(is_draft=False, published_date__lte=timezone.now()) # Written once, called everywhere Article.objects.published()

Both return the same rows today. The difference appears on the day the rule changes, for example when the blog adds a "hidden" flag. The first version must be found and edited in every view that copied it, and one missed copy shows hidden articles. The second version changes in one place.

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content