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
SOS Django Template comes with its own app called core, which adds further functionality to your application. In this section, we will review those.
TimestampModel and ExtendedTimestampModel
In Laravel, the default behavior for migration is to add creation datetime and last update datetime to each model. Of course, you can opt out if you'd like. Django lacks this feature. You wouldn't like to have an unwanted column in your database. However, we can agree that creation datetime and last update datetime fields are widely used and we can add one or two lines of code each time we want them, or we can also define snippets in our editor, that's one of the options, too.
This is what TimestampModel and ExtendedTimestampModel does. Instead of manually adding these line or using snippets, you have a standard way to define them. These models are abstract models, which means you can create a model by extending these.
TimestampModel only adds one field named created_at, which is a DatetimeField with auto_now_add=True, meaning it automatically adds the datetime when a model instance is created.
fromcore.modelsimportTimestampModelclassYourModel(TimestampModel):
# other fields# later in codeyour_model_instance.created_at
ExtendedTimestampModel both adds created_at and a field named last_update, which is a DatetimeField with auto_now=True, meaning it automatically passes the datetime each time a model instance gets updated.
fromcore.modelsimportExtendedTimestampModelclassYourModel(ExtendedTimestampModel):
# other fields# later in codeyour_model_instance.created_atyour_model_instance.last_update
Not Implemented View
There comes a time where you define your URLs in an app of yours with TODOs. Then you want to write views and attach them later on. In those times, you can use not_implemented_view with TODOs so that whenever that URL is hit, you get a NotImplementedError. In order to use that:
# urls.pyfromcore.viewsimportnot_implemented_viewurl_patterns= [
path("home", not_implemented_view, name="home"), # TODO attach home viewpath("about", not_implemented_view, name="about"), # TODO attach about view
]
So when you request /home, you will have a page with error message saying "This view has not been implemented yet.".