The meta of the Django model class is an internal class that defines the behavior characteristics of some Django model classes. Here is a summary of this:
This property is defined as whether the current model class is not an abstract class. The so-called abstract classes do not correspond to database tables. In general, we use it to generalize some common attribute fields, and then inherit its subclasses to inherit those fields. For example, in the following code, human is an abstract class, the employee is a subclass that inherits the human, the human table is not generated when the SYNCDB command is run, but an employee table is generated that contains the fields inherited from human. Later, if you add a customer model class again, it can also inherit the public properties of human:classHuman(Models.Model):
Name=Models.Charfield(Max_length= -)
Gender_choice=((U' M ',U' Male '),(U' F ',U' Female '),)
Gender=Models.Charfield(Max_length=2,Choices=Gender_choice,Null=True)
classMeta:
Abstract=True
classEmployee(Human):
Joint_date=Models.Datefield()
classCustomer(Human):
First_Name=Models.Charfield(Max_length= -)
Birth_day=Models.Datefield()
The above code, after executing python manage.py syncdb output results in, you can see that the human table is not created:
$ python manage.py syncdb
Creating tables ...
Creating Table Myapp_employee
Creating Table Myapp_customer
Installing Custom SQL ...
Installing indexes ...
No fixtures found.
app_label This option is only used in one case, your model class is not in the models.py file under the default application package, you need to specify that the model class is the application. For example, if you write a model class somewhere else, and this model class belongs to MyApp, then you need to specify:App_label=' MyApp '
db_table is used to specify a custom database table name. Django has a set of default database table names that generate the data model according to certain rules, and if you want to use a custom table name, specify it by this attribute, such as:Table_name= ' my_owner_table '
Some databases have database table spaces, such as Oracle. You can use Db_tablespace to specify which database table space the database table for this model is placed in.
because there is a lastest () method in the Django management approach, it is the most recent line of records. If you have a Datefield or Datetimefield type field in your data model, you can use this option to specify which field the lastest () is selected by.
Since Django automatically generates mapped database tables based on the model class, if you do not want Django to do so, you can set the value of managed to false.
This option is typically used in many-to-many relationships, which point to an associated object. This means that the associated object is sorted after it finds the object. After specifying this property you will get a get_xxx_order () and Set_xxx_order () method through which you can set or go back to the sorted object.
This field is the field that tells the Django model object which fields are sorted by which record result sets are returned. For example, the following code:Ordering=[' Order_date '] # Sorted by order ascending
Ordering=['-order_date ']# in descending order of orders-= Descending
Ordering=['? order_date ']# random Sort,? Represents a random
permissions is primarily intended to be used under the Django Admin Management module, and if you set this property you can make the specified method permission description clearer and readable.
This is to implement the proxy model, which is not described in the following article.
unique_together This option is used when you need to remain unique through two fields. For example, suppose you want the combination of a person's FirstName and LastName to be unique, so you need to set this up:Unique_together=(("First_Name","Last_Name"),)
Verbose_name's simple meaning is to give your model class A more readable name:Verbose_name="Pizza"
This option is specified, what is the plural form of the model, for example:
verbose_name_plural = "Stories"
If you do not specify Django will automatically add a ' s ' after the model name
Python model inner class meta-detailed