@@ -41,8 +41,8 @@ class BaseField(object):
4141
4242 def __init__ (self , db_field = None , name = None , required = False , default = None ,
4343 unique = False , unique_with = None , primary_key = False ,
44- validation = None , choices = None , verbose_name = None ,
45- help_text = None , null = False , sparse = False , custom_data = None ):
44+ validation = None , choices = None , null = False , sparse = False ,
45+ ** kwargs ):
4646 """
4747 :param db_field: The database field to store this field in
4848 (defaults to the name of the field)
@@ -60,16 +60,15 @@ def __init__(self, db_field=None, name=None, required=False, default=None,
6060 field. Generally this is deprecated in favour of the
6161 `FIELD.validate` method
6262 :param choices: (optional) The valid choices
63- :param verbose_name: (optional) The verbose name for the field.
64- Designed to be human readable and is often used when generating
65- model forms from the document model.
66- :param help_text: (optional) The help text for this field and is often
67- used when generating model forms from the document model.
6863 :param null: (optional) Is the field value can be null. If no and there is a default value
6964 then the default value is set
7065 :param sparse: (optional) `sparse=True` combined with `unique=True` and `required=False`
7166 means that uniqueness won't be enforced for `None` values
72- :param custom_data: (optional) Custom metadata for this field.
67+ :param **kwargs: (optional) Arbitrary indirection-free metadata for
68+ this field can be supplied as additional keyword arguments and
69+ accessed as attributes of the field. Must not conflict with any
70+ existing attributes. Common metadata includes `verbose_name` and
71+ `help_text`.
7372 """
7473 self .db_field = (db_field or name ) if not primary_key else '_id'
7574
@@ -83,12 +82,19 @@ def __init__(self, db_field=None, name=None, required=False, default=None,
8382 self .primary_key = primary_key
8483 self .validation = validation
8584 self .choices = choices
86- self .verbose_name = verbose_name
87- self .help_text = help_text
8885 self .null = null
8986 self .sparse = sparse
9087 self ._owner_document = None
91- self .custom_data = custom_data
88+
89+ # Detect and report conflicts between metadata and base properties.
90+ conflicts = set (dir (self )) & set (kwargs )
91+ if conflicts :
92+ raise TypeError ("%s already has attribute(s): %s" % (
93+ self .__class__ .__name__ , ', ' .join (conflicts ) ))
94+
95+ # Assign metadata to the instance
96+ # This efficient method is available because no __slots__ are defined.
97+ self .__dict__ .update (kwargs )
9298
9399 # Adjust the appropriate creation counter, and save our local copy.
94100 if self .db_field == '_id' :
0 commit comments