Django的Model上都有些什么
modelinfo=
['DoesNotExist',
'MultipleObjectsReturned',
'__class__',
'__delattr__',
'__dict__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__gt__',
'__hash__',
'__init__',
'__le__',
'__lt__',
'__module__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__setstate__',
'__sizeof__',
'__str__',
'__subclasshook__',
'__weakref__',
'_base_manager',
'_check_column_name_clashes',
'_check_field_name_clashes',
'_check_fields',
'_check_id_field',
'_check_index_together',
'_check_local_fields',
'_check_long_column_names',
'_check_m2m_through_same_relationship',
'_check_managers',
'_check_model',
'_check_ordering',
'_check_swappable',
'_check_unique_together',
'_default_manager',
'_deferred',
'_do_insert',
'_do_update',
'_get_FIELD_display',
'_get_next_or_previous_by_FIELD',
'_get_next_or_previous_in_order',
'_get_pk_val',
'_get_unique_checks',
'_meta',
'_perform_date_checks',
'_perform_unique_checks',
'_save_parents',
'_save_table',
'_set_pk_val',
'adjustment_set',
'check',
'clean',
'clean_fields',
'date_error_message',
'delete',
'employee_in_charge',
'employeeip_set',
'from_db',
'full_clean',
'get_deferred_fields',
'get_next_by_entry_date',
'get_previous_by_entry_date',
'objects',
'pk',
'prepare_database_save',
'punch_set',
'refresh_from_db',
'save',
'save_base',
'serializable_value',
'unique_error_message',
'user',
'validate_unique']
#_meta:
metadata=
['FORWARD_PROPERTIES',
'REVERSE_PROPERTIES',
'__class__',
'__delattr__',
'__dict__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__gt__',
'__hash__',
'__init__',
'__le__',
'__lt__',
'__module__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'__weakref__',
'_expire_cache',
'_forward_fields_map',
'_get_fields',
'_get_fields_cache',
'_map_model',
'_map_model_details',
'_ordering_clash',
'_populate_directed_relation_graph',
'_prepare',
'_relation_tree',
'abstract',
'abstract_managers',
'add_field',
'app_config',
'app_label',
'apps',
'auto_created',
'auto_field',
'can_migrate',
'concrete_fields',
'concrete_managers',
'concrete_model',
'contribute_to_class',
'db_table',
'db_tablespace',
'default_permissions',
'default_related_name',
'fields',
'fields_map',
'get_all_field_names',
'get_all_related_m2m_objects_with_model',
'get_all_related_many_to_many_objects',
'get_all_related_objects',
'get_all_related_objects_with_model',
'get_ancestor_link',
'get_base_chain',
'get_concrete_fields_with_model',
'get_field',
'get_field_by_name',
'get_fields',
'get_fields_with_model',
'get_latest_by',
'get_m2m_with_model',
'get_parent_list',
'has_auto_field',
'index_together',
'installed',
'label',
'label_lower',
'local_concrete_fields',
'local_fields',
'local_many_to_many',
'managed',
'managers',
'many_to_many',
'model',
'model_name',
'object_name',
'order_with_respect_to',
'ordering',
'original_attrs',
'parents',
'permissions',
'pk',
'proxied_children',
'proxy',
'proxy_for_model',
'related_fkey_lookups',
'related_objects',
'required_db_features',
'required_db_vendor',
'select_on_save',
'setup_pk',
'setup_proxy',
'swappable',
'swapped',
'unique_together',
'verbose_name',
'verbose_name_plural',
'verbose_name_raw',
'virtual_fields']
显示Model所有的列名,有两种方法:
- _meta.get_all_field_names() #removed in django 1.10
- _meta.get_fields()
from attendence.models import *
Employee._meta.get_all_field_names() #removed in django 1.10
result=
[
'employeeip',
'first_name',
'entry_date',
'user_id',
'adjustment',
'last_name',
'employee_in_charge',
'user',
'email',
'punch'
]
Employee._meta.get_fields()
result=
(
<ManyToOneRel: attendence.adjustment>,
<ManyToOneRel: attendence.employeeip>,
<ManyToOneRel: attendence.punch>,
<ManyToOneRel: attendence.item>,
<django.db.models.fields.related.OneToOneField: user>,
<django.db.models.fields.CharField: first_name>,
<django.db.models.fields.CharField: last_name>,
<django.db.models.fields.EmailField: email>,
<django.db.models.fields.DateTimeField: entry_date>
)