You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**Do not add trailing spaces at the end of files**
258
303
-**Exception handling:** Be specific with exception types. Avoid catching plain `Exception` when the specific exception that could occur is known. For example, use `Model.DoesNotExist` when calling `.get()` on a Django queryset, or `KeyError` when accessing dictionary keys. This makes error handling more explicit and allows unexpected exceptions to be raised rather than silently caught.
304
+
305
+
### Naming Conventions
306
+
307
+
**Manager Methods:**
308
+
- Custom manager methods should balance conciseness with explicitness
309
+
-**Preferred:** Concise, verb-based names following Django's queryset API patterns: `all()`, `filter()`, `exclude()`, `visible()`, `active()`
310
+
-**Alternative:** Verbose descriptive names when explicitness adds clarity (per "explicit is better than implicit")
311
+
- Choose based on context: if the method name alone isn't clear, add descriptive prefixes
312
+
- If a method returns a queryset, the name should read naturally when chained
313
+
314
+
**Example:**
315
+
```python
316
+
# Preferred - concise, follows Django patterns, clear in context
317
+
GroupProfile.objects.visible(user)
318
+
Article.objects.active()
319
+
Question.objects.recent()
320
+
321
+
# Alternative - more explicit, acceptable when clarity is prioritized
**Pre-commit protection:** A pre-commit hook checks for `.groups.all()` patterns. To bypass for legitimate internal use (like admin or Django internals), add `# noqa: group-leak` comment.
50
+
51
+
**Runtime monitoring:** In development, calls to `user.groups.all()` from views/templates will log security warnings.
0 commit comments