field_name = models.DurationField ( ** options )
Illustration of a DurationField using an example. Consider a project named
pythonengineering that has an application named
Refer to the following articles to check how to create a project and an app in Django.
Enter the following code into the
models.py file of the geeks application.
Now when we run the
makemigrations command from the terminal,
Python manage.py makemigrations
geeks directory cod e> a new folder named migrations will be created with a file named
Python manage.py migrate
geeks_field DurationField is generated when migrations are run in the project. This field is used to store the python
DurationField is used to store python instance
datetime.timedelta code> in the database. You can store any type of time or date based duration in the database. To learn more about
# model import
# from geek apps
# import date and time module
# create an instance
# datetime.timedelta code>
Now let's let's check it on the administrative server. We have created a GeeksModel instance.
Field options — they are arguments given to each field to apply some constraint or to convey a particular characteristic to a particular field. For example, adding the
null = True argument to the DurationField will allow it to store empty values for that table in a relational database.
Here are the field options and attributes that the DurationField can use.
|Null||If True , Django will store empty values as NULL in the database. Default is False.|
|Blank||If True , the field is allowed to be blank ... Default is False.|
|Choices||An iterable (eg, a list or tuple) of 2-tuples to use as choices for this field.|
|Default||The default value for the field. This can be a value or a callable object. If callable it will be called every time a new object is created.|
|help_text||Extra “help” text to be displayed with the form widget. It's useful for documentation even if your field isn't used on a form.|
|primary_key||If True, this field is the primary key for the model .|
|Unique||If True, this field must be unique throughout the table.|
R for Everyone: Advanced Analytics and Graphics. ...
Pandas for Everyone: Python Data Analysis (Addison-Wesley Data & Analytics Series), 1st Edition. Pandas for Everyone brings together the practical knowledge and insights you need to solve real-worl...
Scientific progress has increasingly become reliant on large-scale data collection and analysis methodologies. The same is true for the advanced use of computing in business, government, and other are...
The big data era is upon us: data are being generated, analyzed, and used at an unprecedented scale, and data-driven decision making is sweeping through all aspects of society. Since the value of data...