Listings Model

Learn how to create a model for an app.

Now that we have created the listings app and added it to settings.py, we can proceed to create the listings model in models.py.

"""
ASGI config for example project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'example.settings')

application = get_asgi_application()
Listings model

You can see models.py opened in the widget above. Let’s learn the different components of this code.

Imports

The import in line 1 allows us to create models. Every model that we create will inherit from django.db.models.Model. In other words, each model is a subclass of this import.

The import in line 2 retrieves the current time for each user based on their individual time zones. If users live in different time zones, this import will adjust accordingly.

The last import in line 3 allows us to get the date and time by providing attributes like year, month, day, hour, minute, second, and more. ...