Django

Code

Ticket #5097: model-api.txt.diff

File model-api.txt.diff, 3.4 kB (added by Nicola Larosa <nico@teknico.net>, 1 year ago)
  • model-api.txt

    old new  
    150150provide consistency throughout Django. There is full legacy support for 
    151151the old ``maxlength`` argument, but ``max_length`` is prefered. 
    152152         
    153  ``CommaSeparatedIntegerField`` 
     153``CommaSeparatedIntegerField`` 
    154154~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    155155 
    156156A field of integers separated by commas. As in ``CharField``, the ``max_length`` 
     
    737737To define a many-to-one relationship, use ``ForeignKey``. You use it just like 
    738738any other ``Field`` type: by including it as a class attribute of your model. 
    739739 
    740 ``ForeignKey`` requires a positional argument: The class to which the model is 
     740``ForeignKey`` requires a positional argument: the class to which the model is 
    741741related. 
    742742 
    743743For example, if a ``Car`` model has a ``Manufacturer`` -- that is, a 
     
    872872like any other ``Field`` type: by including it as a class attribute of your 
    873873model. 
    874874 
    875 ``ManyToManyField`` requires a positional argument: The class to which the 
     875``ManyToManyField`` requires a positional argument: the class to which the 
    876876model is related. 
    877877 
    878878For example, if a ``Pizza`` has multiple ``Topping`` objects -- that is, a 
     
    969969This is most useful on the primary key of an object when that object "extends" 
    970970another object in some way. 
    971971 
    972 ``OneToOneField`` requires a positional argument: The class to which the 
     972``OneToOneField`` requires a positional argument: the class to which the 
    973973model is related. 
    974974 
    975975For example, if you're building a database of "places", you would build pretty 
     
    14211421 
    14221422A few special cases to note about ``list_display``: 
    14231423 
    1424     * If the field is a ``ForeignKey``, Django will display the ``__str__()`` 
    1425       of the related object. 
     1424    * If the field is a ``ForeignKey``, Django will display the 
     1425      ``__unicode__()`` of the related object. 
    14261426 
    14271427    * ``ManyToManyField`` fields aren't supported, because that would entail 
    14281428      executing a separate SQL statement for each row in the table. If you 
     
    16721672        AND (first_name ILIKE 'lennon' OR last_name ILIKE 'lennon') 
    16731673 
    16741674    Note that the query input is split by spaces, so, following this example, 
    1675     it's not currently not possible to search for all records in which 
     1675    it's currently not possible to search for all records in which 
    16761676    ``first_name`` is exactly ``'john winston'`` (containing a space). 
    16771677 
    16781678``@`` 
     
    19561956use ``get_absolute_url()`` as a convenience to reward people who've defined the 
    19571957method. 
    19581958 
    1959 .. syndication feed framework: ../syndication_feeds/ 
     1959.. _syndication feed framework: ../syndication_feeds/ 
    19601960 
    19611961It's good practice to use ``get_absolute_url()`` in templates, instead of 
    19621962hard-coding your objects' URLs. For example, this template code is bad:: 
     
    20152015            'day': self.created.day}) 
    20162016    get_absolute_url = permalink(get_absolute_url) 
    20172017 
    2018 Notice that we specify an empty sequence for the second argument in this case, 
    2019 because we only want to pass keyword arguments, not named arguments. 
     2018Notice that we specify an empty sequence for the second parameter in this case, 
     2019because we only want to pass keyword parameters, not positional ones. 
    20202020 
    20212021In this way, you're tying the model's absolute URL to the view that is used 
    20222022to display it, without repeating the URL information anywhere. You can still