1. Demand
The Django models defines the tables of the database, and many of the tables in the process must have many common operations. Then you can encapsulate some of the common operations, and you don't need to repeat the definition and use in each table.
2. Definition
or inherit from models, define a Jsonmode base class
Class Jsonmode (models. Model):
2.1 Virtualization
#Model基类, you're not going to create a data table
#默认按照时间逆序排列
Class Meta:
abstract = True
2.2 Public fields, such as sort
#Model基类, you're not going to create a data table
#默认按照时间逆序排列
Class Meta:
abstract = True
ordering = ['-modifytime ', '-createtime ', '-id ']
3. Public functions
For example, some of the functions are selected, and this function has normal argument self and other parameters
3.1 Field operations that are not yet defined
It is particularly important to note that, depending on the column name, the following actions are generally required to models the data fields.
Self.name = ' This is a test '
In Jsonmode, ColName is passed in by parameters, you can use the properties of the Python object to set functions and get functions setattr and GetAttr
#根据列名, the old value is retained, the new value is temporarily placed at the end, and the callback is refreshed after the file is successfully uploaded
SetAttr (Self, colname,getattr (Self,colname, ") + Globalvar.interstr + filename[0])
Method Invocation of 3.2 models
Models method call, directly using the self call, such as Self.save ()
4, sub-class implementation
For example, Filtetemp inherits Jsonmode and calls the parent class's function using Super (FILETEMP,SERL). function can be
"Django Models" virtualization extracts Models public functionality