Changeset 212
- Timestamp:
- 07/19/05 12:20:37 (3 years ago)
- Files:
-
- django/trunk/django/core/meta.py (modified) (14 diffs)
- django/trunk/docs/db-api.txt (modified) (3 diffs)
- django/trunk/docs/model-api.txt (modified) (3 diffs)
- django/trunk/docs/overview.txt (modified) (4 diffs)
- django/trunk/docs/tutorial01.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/meta.py
r161 r212 1565 1565 empty_strings_allowed = True 1566 1566 1567 def __init__(self, name, verbose_name , primary_key=False,1567 def __init__(self, name, verbose_name=None, primary_key=False, 1568 1568 maxlength=None, unique=False, blank=False, null=False, db_index=None, 1569 1569 core=False, rel=None, default=NOT_PROVIDED, editable=True, … … 1571 1571 unique_for_year=None, validator_list=None, choices=None, radio_admin=None, 1572 1572 help_text=''): 1573 self.name, self.verbose_name = name, verbose_name 1573 self.name = name 1574 self.verbose_name = verbose_name or name.replace('_', ' ') 1574 1575 self.primary_key = primary_key 1575 1576 self.maxlength, self.unique = maxlength, unique … … 1768 1769 1769 1770 class BooleanField(Field): 1770 def __init__(self, name, verbose_name, **kwargs):1771 def __init__(self, *args, **kwargs): 1771 1772 kwargs['blank'] = True 1772 Field.__init__(self, name, verbose_name, **kwargs)1773 Field.__init__(self, *args, **kwargs) 1773 1774 1774 1775 def get_manipulator_field_objs(self): … … 1785 1786 class DateField(Field): 1786 1787 empty_strings_allowed = False 1787 def __init__(self, name, verbose_name , auto_now=False, auto_now_add=False, **kwargs):1788 def __init__(self, name, verbose_name=None, auto_now=False, auto_now_add=False, **kwargs): 1788 1789 self.auto_now, self.auto_now_add = auto_now, auto_now_add 1789 1790 if auto_now or auto_now_add: … … 1841 1842 1842 1843 class FileField(Field): 1843 def __init__(self, name, verbose_name , upload_to='', **kwargs):1844 def __init__(self, name, verbose_name=None, upload_to='', **kwargs): 1844 1845 self.upload_to = upload_to 1845 1846 Field.__init__(self, name, verbose_name, **kwargs) … … 1906 1907 class FloatField(Field): 1907 1908 empty_strings_allowed = False 1908 def __init__(self, name, verbose_name , max_digits, decimal_places, **kwargs):1909 def __init__(self, name, verbose_name=None, max_digits=None, decimal_places=None, **kwargs): 1909 1910 self.max_digits, self.decimal_places = max_digits, decimal_places 1910 1911 Field.__init__(self, name, verbose_name, **kwargs) … … 1914 1915 1915 1916 class ImageField(FileField): 1916 def __init__(self, name, verbose_name , width_field=None, height_field=None, **kwargs):1917 def __init__(self, name, verbose_name=None, width_field=None, height_field=None, **kwargs): 1917 1918 self.width_field, self.height_field = width_field, height_field 1918 1919 FileField.__init__(self, name, verbose_name, **kwargs) … … 1939 1940 1940 1941 class IPAddressField(Field): 1941 def __init__(self, name, verbose_name, **kwargs):1942 def __init__(self, *args, **kwargs): 1942 1943 kwargs['maxlength'] = 15 1943 Field.__init__(self, name, verbose_name, **kwargs)1944 Field.__init__(self, *args, **kwargs) 1944 1945 1945 1946 def get_manipulator_field_objs(self): … … 1947 1948 1948 1949 class NullBooleanField(Field): 1949 def __init__(self, name, verbose_name, **kwargs):1950 def __init__(self, *args, **kwargs): 1950 1951 kwargs['null'] = True 1951 Field.__init__(self, name, verbose_name, **kwargs)1952 Field.__init__(self, *args, **kwargs) 1952 1953 1953 1954 def get_manipulator_field_objs(self): … … 1967 1968 1968 1969 class SlugField(Field): 1969 def __init__(self, name, verbose_name, **kwargs):1970 def __init__(self, *args, **kwargs): 1970 1971 kwargs['maxlength'] = 50 1971 1972 kwargs.setdefault('validator_list', []).append(validators.isAlphaNumeric) … … 1973 1974 if not kwargs.has_key('db_index'): 1974 1975 kwargs['db_index'] = True 1975 Field.__init__(self, name, verbose_name, **kwargs)1976 Field.__init__(self, *args, **kwargs) 1976 1977 1977 1978 def get_manipulator_field_objs(self): … … 1988 1989 class TimeField(Field): 1989 1990 empty_strings_allowed = False 1990 def __init__(self, name, verbose_name , auto_now=False, auto_now_add=False, **kwargs):1991 def __init__(self, name, verbose_name=None, auto_now=False, auto_now_add=False, **kwargs): 1991 1992 self.auto_now, self.auto_now_add = auto_now, auto_now_add 1992 1993 if auto_now or auto_now_add: … … 2015 2016 2016 2017 class URLField(Field): 2017 def __init__(self, name, verbose_name , verify_exists=True, **kwargs):2018 def __init__(self, name, verbose_name=None, verify_exists=True, **kwargs): 2018 2019 if verify_exists: 2019 2020 kwargs.setdefault('validator_list', []).append(validators.isExistingURL) … … 2028 2029 2029 2030 class XMLField(Field): 2030 def __init__(self, name, verbose_name , schema_path, **kwargs):2031 def __init__(self, name, verbose_name=None, schema_path=None, **kwargs): 2031 2032 self.schema_path = schema_path 2032 2033 Field.__init__(self, name, verbose_name, **kwargs) django/trunk/docs/db-api.txt
r211 r212 13 13 class Poll(meta.Model): 14 14 fields = ( 15 meta.SlugField('slug', 'slug',unique_for_month='pub_date'),16 meta.CharField('question', 'question',maxlength=255),17 meta.DateTimeField('pub_date' , 'date published'),18 meta.DateTimeField('expire_date' , 'expiration date'),15 meta.SlugField('slug', unique_for_month='pub_date'), 16 meta.CharField('question', maxlength=255), 17 meta.DateTimeField('pub_date'), 18 meta.DateTimeField('expire_date'), 19 19 ) 20 20 … … 23 23 meta.ForeignKey(Poll, edit_inline=True, edit_inline_type=meta.TABULAR, 24 24 num_in_admin=10, min_num_in_admin=5), 25 meta.CharField('choice', 'choice',maxlength=255, core=True),26 meta.IntegerField('votes', 'votes',editable=False, default=0),25 meta.CharField('choice', maxlength=255, core=True), 26 meta.IntegerField('votes', editable=False, default=0), 27 27 ) 28 28 … … 352 352 ================ 353 353 354 Just cause we're crazy like that, the delete method is named ``delete()``. 355 Yeah, you never know what we're going to do next. 356 354 The delete method, conveniently, is named ``delete()``. django/trunk/docs/model-api.txt
r184 r212 35 35 36 36 fields = ( 37 meta.CharField('customer_name', 'customer name',maxlength=15),38 meta.BooleanField('use_extra_cheese' , 'use extra cheese'),39 meta.IntegerField('customer_type', 'customer type',choices=CUSTOMER_TYPE_CHOICES),37 meta.CharField('customer_name', maxlength=15), 38 meta.BooleanField('use_extra_cheese'), 39 meta.IntegerField('customer_type', choices=CUSTOMER_TYPE_CHOICES), 40 40 ... 41 41 ) … … 124 124 125 125 All field objects -- except for ``ForeignKey`` and ``ManyToManyField`` (see 126 below) -- take two positional arguments and a number of keyword arguments. 127 The positional arguments are the field name and the human-readable name. The 128 field name must be a valid Python identifier, but the human-readable name can 129 contain spaces, punctuation, etc. 126 below) -- require the field's machine-readable name as the first positional 127 argument. This must be a valid Python identifier -- no spaces, punctuation, 128 etc., are allowed. 129 130 The second positional argument, a human-readable name, is optional. If the 131 human-readable name isn't given, Django will use the machine-readable name, 132 coverting underscores to spaces. 130 133 131 134 General field options … … 227 230 model if you don't specify otherwise. That automatically-added field is:: 228 231 229 meta.AutoField('id', 'ID',primary_key=True)232 meta.AutoField('id', primary_key=True) 230 233 231 234 ``BooleanField`` django/trunk/docs/overview.txt
r192 r212 23 23 class Reporter(meta.Model): 24 24 fields = ( 25 meta.CharField('full_name', "reporter's full name",maxlength=70),25 meta.CharField('full_name', maxlength=70), 26 26 ) 27 27 … … 31 31 class Article(meta.Model): 32 32 fields = ( 33 meta.DateTimeField('pub_date' , 'publication date'),34 meta.CharField('headline', 'headline',maxlength=200),35 meta.TextField('article' , 'article'),33 meta.DateTimeField('pub_date'), 34 meta.CharField('headline', maxlength=200), 35 meta.TextField('article'), 36 36 meta.ForeignKey(Reporter), 37 37 ) … … 134 134 class Article(meta.Model): 135 135 fields = ( 136 meta.DateTimeField('pub_date' , 'publication date'),137 meta.CharField('headline', 'headline',maxlength=200),138 meta.TextField('article' , 'article'),136 meta.DateTimeField('pub_date'), 137 meta.CharField('headline', maxlength=200), 138 meta.TextField('article'), 139 139 meta.ForeignKey(Reporter), 140 140 ) … … 303 303 small Python class. 304 304 * More sexy automatically-generated admin features -- this overview barely 305 scratched the surface 306 307 The next obvious steps are for you to download Django, read the documentation 308 and join the community. Thanks for your interest! 305 scratched the surface. 306 307 The next obvious steps are for you to `download Django`_, read `the tutorial`_ 308 and join `the community`_. Thanks for your interest! 309 310 .. _download Django: http://www.djangoproject.com/documentation/ 311 .. _the tutorial: http://www.djangoproject.com/documentation/tutorial1/ 312 .. _the community: http://www.djangoproject.com/community/ django/trunk/docs/tutorial01.txt
r163 r212 138 138 class Poll(meta.Model): 139 139 fields = ( 140 meta.CharField('question', 'question',maxlength=200),140 meta.CharField('question', maxlength=200), 141 141 meta.DateTimeField('pub_date', 'date published'), 142 142 ) … … 145 145 fields = ( 146 146 meta.ForeignKey(Poll), 147 meta.CharField('choice', 'choice',maxlength=200),148 meta.IntegerField('votes' , 'votes'),147 meta.CharField('choice', maxlength=200), 148 meta.IntegerField('votes'), 149 149 ) 150 150 … … 161 161 database will use it as the column name. 162 162 163 The second argument is the field's human-readable name. That's used in a couple 164 of introspective parts of Django, and it doubles as documentation. 163 The second, optional, argument is the field's human-readable name. That's used 164 in a couple of introspective parts of Django, and it doubles as documentation. 165 If this field isn't provided, Django will use the machine-readable name. In 166 this example, we've only defined a human-readable name for ``Poll.pub_date``. 167 For all other fields in this model, the field's machine-readable name will 168 suffice as its human-readable name. 165 169 166 170 Some ``meta.*Field`` classes have additional required elements.
