Django

Code

Changeset 212

Show
Ignore:
Timestamp:
07/19/05 12:20:37 (3 years ago)
Author:
adrian
Message:

Fixed #67 -- Human-readable name is now optional in model fields. If a second positional argument isn't given, Django will use the first argument, converting underscores to spaces. This change is fully backwards-compatible.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/meta.py

    r161 r212  
    15651565    empty_strings_allowed = True 
    15661566 
    1567     def __init__(self, name, verbose_name, primary_key=False, 
     1567    def __init__(self, name, verbose_name=None, primary_key=False, 
    15681568        maxlength=None, unique=False, blank=False, null=False, db_index=None, 
    15691569        core=False, rel=None, default=NOT_PROVIDED, editable=True, 
     
    15711571        unique_for_year=None, validator_list=None, choices=None, radio_admin=None, 
    15721572        help_text=''): 
    1573         self.name, self.verbose_name = name, verbose_name 
     1573        self.name = name 
     1574        self.verbose_name = verbose_name or name.replace('_', ' ') 
    15741575        self.primary_key = primary_key 
    15751576        self.maxlength, self.unique = maxlength, unique 
     
    17681769 
    17691770class BooleanField(Field): 
    1770     def __init__(self, name, verbose_name, **kwargs): 
     1771    def __init__(self, *args, **kwargs): 
    17711772        kwargs['blank'] = True 
    1772         Field.__init__(self, name, verbose_name, **kwargs) 
     1773        Field.__init__(self, *args, **kwargs) 
    17731774 
    17741775    def get_manipulator_field_objs(self): 
     
    17851786class DateField(Field): 
    17861787    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): 
    17881789        self.auto_now, self.auto_now_add = auto_now, auto_now_add 
    17891790        if auto_now or auto_now_add: 
     
    18411842 
    18421843class FileField(Field): 
    1843     def __init__(self, name, verbose_name, upload_to='', **kwargs): 
     1844    def __init__(self, name, verbose_name=None, upload_to='', **kwargs): 
    18441845        self.upload_to = upload_to 
    18451846        Field.__init__(self, name, verbose_name, **kwargs) 
     
    19061907class FloatField(Field): 
    19071908    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): 
    19091910        self.max_digits, self.decimal_places = max_digits, decimal_places 
    19101911        Field.__init__(self, name, verbose_name, **kwargs) 
     
    19141915 
    19151916class 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): 
    19171918        self.width_field, self.height_field = width_field, height_field 
    19181919        FileField.__init__(self, name, verbose_name, **kwargs) 
     
    19391940 
    19401941class IPAddressField(Field): 
    1941     def __init__(self, name, verbose_name, **kwargs): 
     1942    def __init__(self, *args, **kwargs): 
    19421943        kwargs['maxlength'] = 15 
    1943         Field.__init__(self, name, verbose_name, **kwargs) 
     1944        Field.__init__(self, *args, **kwargs) 
    19441945 
    19451946    def get_manipulator_field_objs(self): 
     
    19471948 
    19481949class NullBooleanField(Field): 
    1949     def __init__(self, name, verbose_name, **kwargs): 
     1950    def __init__(self, *args, **kwargs): 
    19501951        kwargs['null'] = True 
    1951         Field.__init__(self, name, verbose_name, **kwargs) 
     1952        Field.__init__(self, *args, **kwargs) 
    19521953 
    19531954    def get_manipulator_field_objs(self): 
     
    19671968 
    19681969class SlugField(Field): 
    1969     def __init__(self, name, verbose_name, **kwargs): 
     1970    def __init__(self, *args, **kwargs): 
    19701971        kwargs['maxlength'] = 50 
    19711972        kwargs.setdefault('validator_list', []).append(validators.isAlphaNumeric) 
     
    19731974        if not kwargs.has_key('db_index'): 
    19741975            kwargs['db_index'] = True 
    1975         Field.__init__(self, name, verbose_name, **kwargs) 
     1976        Field.__init__(self, *args, **kwargs) 
    19761977 
    19771978    def get_manipulator_field_objs(self): 
     
    19881989class TimeField(Field): 
    19891990    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): 
    19911992        self.auto_now, self.auto_now_add  = auto_now, auto_now_add 
    19921993        if auto_now or auto_now_add: 
     
    20152016 
    20162017class 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): 
    20182019        if verify_exists: 
    20192020            kwargs.setdefault('validator_list', []).append(validators.isExistingURL) 
     
    20282029 
    20292030class XMLField(Field): 
    2030     def __init__(self, name, verbose_name, schema_path, **kwargs): 
     2031    def __init__(self, name, verbose_name=None, schema_path=None, **kwargs): 
    20312032        self.schema_path = schema_path 
    20322033        Field.__init__(self, name, verbose_name, **kwargs) 
  • django/trunk/docs/db-api.txt

    r211 r212  
    1313    class Poll(meta.Model): 
    1414        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'), 
    1919        ) 
    2020 
     
    2323            meta.ForeignKey(Poll, edit_inline=True, edit_inline_type=meta.TABULAR, 
    2424                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), 
    2727        ) 
    2828 
     
    352352================ 
    353353 
    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  
     354The delete method, conveniently, is named ``delete()``. 
  • django/trunk/docs/model-api.txt

    r184 r212  
    3535 
    3636        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), 
    4040            ... 
    4141        ) 
     
    124124 
    125125All 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. 
     126below) -- require the field's machine-readable name as the first positional 
     127argument. This must be a valid Python identifier -- no spaces, punctuation, 
     128etc., are allowed. 
     129 
     130The second positional argument, a human-readable name, is optional. If the 
     131human-readable name isn't given, Django will use the machine-readable name, 
     132coverting underscores to spaces. 
    130133 
    131134General field options 
     
    227230    model if you don't specify otherwise. That automatically-added field is:: 
    228231 
    229         meta.AutoField('id', 'ID', primary_key=True) 
     232        meta.AutoField('id', primary_key=True) 
    230233 
    231234``BooleanField`` 
  • django/trunk/docs/overview.txt

    r192 r212  
    2323    class Reporter(meta.Model): 
    2424        fields = ( 
    25             meta.CharField('full_name', "reporter's full name", maxlength=70), 
     25            meta.CharField('full_name', maxlength=70), 
    2626        ) 
    2727 
     
    3131    class Article(meta.Model): 
    3232        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'), 
    3636            meta.ForeignKey(Reporter), 
    3737        ) 
     
    134134    class Article(meta.Model): 
    135135        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'), 
    139139            meta.ForeignKey(Reporter), 
    140140        ) 
     
    303303      small Python class. 
    304304    * 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 
     307The next obvious steps are for you to `download Django`_, read `the tutorial`_ 
     308and 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  
    138138    class Poll(meta.Model): 
    139139        fields = ( 
    140             meta.CharField('question', 'question', maxlength=200), 
     140            meta.CharField('question', maxlength=200), 
    141141            meta.DateTimeField('pub_date', 'date published'), 
    142142        ) 
     
    145145        fields = ( 
    146146            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'), 
    149149        ) 
    150150 
     
    161161database will use it as the column name. 
    162162 
    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. 
     163The second, optional, argument is the field's human-readable name. That's used 
     164in a couple of introspective parts of Django, and it doubles as documentation. 
     165If this field isn't provided, Django will use the machine-readable name. In 
     166this example, we've only defined a human-readable name for ``Poll.pub_date``. 
     167For all other fields in this model, the field's machine-readable name will 
     168suffice as its human-readable name. 
    165169 
    166170Some ``meta.*Field`` classes have additional required elements.