Ticket #5097: model-api.txt.diff
File model-api.txt.diff, 3.4 KB (added by , 17 years ago) |
---|
-
model-api.txt
150 150 provide consistency throughout Django. There is full legacy support for 151 151 the old ``maxlength`` argument, but ``max_length`` is prefered. 152 152 153 153 ``CommaSeparatedIntegerField`` 154 154 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 155 155 156 156 A field of integers separated by commas. As in ``CharField``, the ``max_length`` … … 737 737 To define a many-to-one relationship, use ``ForeignKey``. You use it just like 738 738 any other ``Field`` type: by including it as a class attribute of your model. 739 739 740 ``ForeignKey`` requires a positional argument: The class to which the model is740 ``ForeignKey`` requires a positional argument: the class to which the model is 741 741 related. 742 742 743 743 For example, if a ``Car`` model has a ``Manufacturer`` -- that is, a … … 872 872 like any other ``Field`` type: by including it as a class attribute of your 873 873 model. 874 874 875 ``ManyToManyField`` requires a positional argument: The class to which the875 ``ManyToManyField`` requires a positional argument: the class to which the 876 876 model is related. 877 877 878 878 For example, if a ``Pizza`` has multiple ``Topping`` objects -- that is, a … … 969 969 This is most useful on the primary key of an object when that object "extends" 970 970 another object in some way. 971 971 972 ``OneToOneField`` requires a positional argument: The class to which the972 ``OneToOneField`` requires a positional argument: the class to which the 973 973 model is related. 974 974 975 975 For example, if you're building a database of "places", you would build pretty … … 1421 1421 1422 1422 A few special cases to note about ``list_display``: 1423 1423 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. 1426 1426 1427 1427 * ``ManyToManyField`` fields aren't supported, because that would entail 1428 1428 executing a separate SQL statement for each row in the table. If you … … 1672 1672 AND (first_name ILIKE 'lennon' OR last_name ILIKE 'lennon') 1673 1673 1674 1674 Note that the query input is split by spaces, so, following this example, 1675 it's notcurrently not possible to search for all records in which1675 it's currently not possible to search for all records in which 1676 1676 ``first_name`` is exactly ``'john winston'`` (containing a space). 1677 1677 1678 1678 ``@`` … … 1956 1956 use ``get_absolute_url()`` as a convenience to reward people who've defined the 1957 1957 method. 1958 1958 1959 .. syndication feed framework: ../syndication_feeds/1959 .. _syndication feed framework: ../syndication_feeds/ 1960 1960 1961 1961 It's good practice to use ``get_absolute_url()`` in templates, instead of 1962 1962 hard-coding your objects' URLs. For example, this template code is bad:: … … 2015 2015 'day': self.created.day}) 2016 2016 get_absolute_url = permalink(get_absolute_url) 2017 2017 2018 Notice that we specify an empty sequence for the second argumentin this case,2019 because we only want to pass keyword arguments, not named arguments.2018 Notice that we specify an empty sequence for the second parameter in this case, 2019 because we only want to pass keyword parameters, not positional ones. 2020 2020 2021 2021 In this way, you're tying the model's absolute URL to the view that is used 2022 2022 to display it, without repeating the URL information anywhere. You can still