Skip to content

Instantly share code, notes, and snippets.

Git Commit Style Guide

Inspiration: Deis Commit Style Guide

I often quote Deis in sections below.

Motivation

It makes going back and reading commits easier. It also allows you to spend less time thinking about what your commit message should be.

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@suspiciousRaccoon
suspiciousRaccoon / mixins.py
Created February 15, 2024 00:18
Django - Automatically add the request user to a form field in CBV via mixin
from django.contrib.auth.mixins import LoginRequiredMixin
class SetUserMixin(LoginRequiredMixin):
"""
Automatically add `self.request.user` to a specified `user_field`. `use_field` defaults to "user"
"""
user_field = "user"
@suspiciousRaccoon
suspiciousRaccoon / forms.py
Created March 13, 2024 01:43
Mixins for passing the request to a form in django
class BlogForm(GetRequestFromFormMixin, forms.ModelForm):
class Meta:
model = Blog
fields = ("name, description",)
def clean(self):
print(self.request) # we can now access the request!
return super().clean()

Common Django Pitfalls

This contains a collection of common errors people make when coding Django apps, and how to fix them.

Important Strategies for preventing pitfalls

  1. Always do one thing at a time and test it. Make a single change, test it for errors, before moving on to the next thing.
  2. When trying to fix an error, only change one thing at a time, If the error message does not change, undo that change and try something else.
  3. If you discover you haven't saved a file, and that's causing an error, save the file and try again and pay attention to any new errors. The original error isn't worth worrying about until you have saved everything