Angular, Blockchain, Science とか

Angular, Blockchain, Science全般 の情報を主に書いていきます。

djangoのmodel の個人的メモ

個人的なメモです もしかしたら役に立つかもしれません

arguments: auto_now which automatically set the field to now every time the object is saved, and auto_now_add which automatically set the field to now when the object is first created.

auto_now は更新するたびにその時間を記録、auto_now_add は最初に作ったときの時間をずっと記録。

ImageFeilds は Pillow が必要。Pillowの勉強もちゃんとする必要あり。

Cascade deletes. Django emulates the behavior of the SQL constraint ON DELETE CASCADE and also deletes the object containing the ForeignKey.

Abstract base classes are useful when you want to put some common information into a number of other models. You write your base class and put abstract=True in the Meta class. This model will then not be used to create any database table. Instead, when it is used as a base class for other models, its fields will be added to those of the child class.

オブジェクト指向のインターフェースみたいなもの

class Meta:
    abstract = True

Model の method はオーバーライド 

It’s important to remember to call the superclass method – that’s that super(Blog, self).save(*args, **kwargs) business – to ensure that the object still gets saved into the database. If you forget to call the superclass method, the default behavior won’t happen and the database won’t get touched.

If you use *args, **kwargs in your method definitions, you are guaranteed that your code will automatically support those arguments when they are added.

if you only want to modify the Python-level behavior of a model, without changing the models fields in any way, you can use Proxy models.

verbose = 詳細