Django

Code

Changeset 5264

Show
Ignore:
Timestamp:
05/16/07 16:34:43 (1 year ago)
Author:
adrian
Message:

Added some Django-specific style guidelines to docs/contributing.txt, which I've been meaning to do for a while

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/contributing.txt

    r5160 r5264  
    280280      for details. 
    281281 
    282     * In Django template code, put one (and only one) space between the curly 
    283       brackets and the tag contents. 
    284  
    285       Do this:: 
    286  
    287           {{ foo }} 
    288  
    289       Don't do this:: 
    290  
    291           {{foo}} 
    292  
    293     * In Django views, the first parameter in a view function should be called 
    294       ``request``. 
    295  
    296       Do this:: 
    297  
    298           def my_view(request, foo): 
    299               # ... 
    300  
    301       Don't do this:: 
    302  
    303           def my_view(req, foo): 
    304               # ... 
    305  
    306282    * Please don't put your name in the code you contribute. Our policy is to 
    307283      keep contributors' names in the ``AUTHORS`` file distributed with Django 
     
    309285      change to the ``AUTHORS`` file in your patch if you make more than a 
    310286      single trivial change. 
     287 
     288Template style 
     289-------------- 
     290 
     291    * In Django template code, put one (and only one) space between the curly 
     292      brackets and the tag contents. 
     293 
     294      Do this:: 
     295 
     296          {{ foo }} 
     297 
     298      Don't do this:: 
     299 
     300          {{foo}} 
     301 
     302View style 
     303---------- 
     304 
     305    * In Django views, the first parameter in a view function should be called 
     306      ``request``. 
     307 
     308      Do this:: 
     309 
     310          def my_view(request, foo): 
     311              # ... 
     312 
     313      Don't do this:: 
     314 
     315          def my_view(req, foo): 
     316              # ... 
     317 
     318Model style 
     319----------- 
     320 
     321    * Field names should be all lowercase, using underscores instead of 
     322      camelCase. 
     323 
     324      Do this:: 
     325 
     326          class Person(models.Model): 
     327              first_name = models.CharField(maxlength=20) 
     328              last_name = models.CharField(maxlength=40) 
     329 
     330      Don't do this:: 
     331 
     332          class Person(models.Model): 
     333              FirstName = models.CharField(maxlength=20) 
     334              Last_Name = models.CharField(maxlength=40) 
     335 
     336    * The ``class Meta`` should appear *after* the fields are defined, with 
     337      a single blank line separating the fields and the class definition. 
     338 
     339      Do this:: 
     340 
     341          class Person(models.Model): 
     342              first_name = models.CharField(maxlength=20) 
     343              last_name = models.CharField(maxlength=40) 
     344 
     345              class Meta: 
     346                  verbose_name_plural = 'people' 
     347 
     348      Don't do this:: 
     349 
     350          class Person(models.Model): 
     351              FirstName = models.CharField(maxlength=20) 
     352              Last_Name = models.CharField(maxlength=40) 
     353              class Meta: 
     354                  verbose_name_plural = 'people' 
     355 
     356      Don't do this, either:: 
     357 
     358          class Person(models.Model): 
     359              class Meta: 
     360                  verbose_name_plural = 'people' 
     361 
     362              FirstName = models.CharField(maxlength=20) 
     363              Last_Name = models.CharField(maxlength=40) 
     364 
     365    * The order of model inner classes and standard methods should be as 
     366      follows (noting that these are not all required): 
     367 
     368        * All database fields 
     369        * ``class Meta`` 
     370        * ``class Admin`` 
     371        * ``def __str__()`` 
     372        * ``def save()`` 
     373        * ``def get_absolute_url()`` 
     374        * Any custom methods 
     375 
     376    * If ``choices`` is defined for a given model field, define the choices as 
     377      a tuple of tuples, with an all-uppercase name, either near the top of the 
     378      model module or just above the model class. Example:: 
     379 
     380          GENDER_CHOICES = ( 
     381              ('M', 'Male'), 
     382              ('F', 'Female'), 
     383          ) 
    311384 
    312385Committing code