Unterammergau, Bavaria, Germany — Dec 2019

Some points to consider when choosing between or model .save() method to perform additional tasks when writing into databases.

These are not golden rules but for reference only.

Override .save() when

  • Model values must be modified or transformed before saving into the database. Do it in .save() so it won’t fail.
  • The manipulation applies to the model instance itself, instead of side-effects to other objects.
  • For better readability as codes are placed together. The business logic in .save() stays closely with the model definitions.

Use Django signals when

  • Model values can be saved safely without intervention or clean up, so no need to customize…

Königssee, Bavaria, Germany — Dec 2019

By default, Django adds the auto-incrementing primary key to each model when we do not specify a custom primary key field.

id = models.AutoField(primary_key=True)

It is beneficial most of the time since the ID is generated by the database and automatically increases according to the available values, so we do not need to worry about setting the value by ourselves and having colliding IDs.

Internal vs. External Primary Key

But sometimes we would like to have another unique but not auto-incrementing value as the identifier, serving as a “pseudo primary key” and hiding the actual ID in the database. …

Zugspitze, Germany — Dec 2019

Altering your data models or schema is sometimes inexorable due to changing requirements or fixing legacy design mistakes. It can be a risky refactoring task since the data models are the core of the application, which is also stateful and one would need to take care of compatibility. We also need to be mindful to avoid any customer data loss and minimize the downtime as much as possible.

With the help of ORM frameworks such as Django, modifying database schema is getting easier since the framework can automatically generate SQL migration scripts like ALTER TABLE, ALTER COLUMN or CREATE INDEX

Passing ID vs. Entity as props in React
Passing ID vs. Entity as props in React
Königssee, Bavaria, Germany — Dec 2019

Passing props between components is inevitable when writing React applications. But have you ever wonder:

Should the parent component pass the domain entity/object or just the ID of the object into the child component?

And how would this affect the boundaries of smart vs. dumb components?

Recap on Smart vs. Dumb components

There are a lot of great articles covering this pattern and illustrating the advantages. I have also briefly mentioned the concept of smart and dumb components in my , but let’s do a quick recap here.

In the early days, class components have been doing the heavy-lifting works such as data fetching, state…

Teufelstättkopf, Bavaria, Germany — Dec 2019

In this post, I would like to share a brief history of ReactJS and its solutions to state management. You may probably know these already, but I think it would give a glimpse of how React evolves all the way long for those who are new to this framework, or a quick refresh if you are a veteran.

Two Camps of Components

React has two types of components — Class-based and Functional. As the names suggest, class components inherit React.Component


Software Engineer | Hongkonger 🇭🇰 Passion for Craftsmanship

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store