Ticket #10903: 10903.diff

File 10903.diff, 2.2 KB (added by Tim Graham, 15 years ago)

initial patch looks solid, just tweaking some links and grammar

  • docs/topics/db/queries.txt

     
    819819    # THIS WILL RAISE A FieldError
    820820    >>> Entry.objects.update(headline=F('blog__name'))
    821821
     822.. _topics-db-queries-related:
     823
    822824Related objects
    823825===============
    824826
  • docs/topics/templates.txt

     
    576576The variable's contents are still automatically escaped, if necessary, because
    577577they're beyond the control of the template author.
    578578
     579.. _template-accessing-methods:
     580
     581Accessing method calls
     582======================
     583
     584Most method calls attached to objects are also available from within templates.
     585This means that templates have access to much more than just class attributes
     586(like field names) and variables passed in from views. For example, the Django
     587ORM provides the :ref:`"entry_set"<topics-db-queries-related>` syntax for
     588finding a collection of objects related on a foreign key. Therefore, given
     589a model called "comment" with a foreign key relationship to a model called
     590"task" you can loop through all comments attached to a given task like this::
     591
     592    {% for comment in task.comment_set.all %}
     593        {{ comment }}
     594    {% endfor %}
     595
     596Similarly, :ref:`QuerySets<ref-models-querysets>` provide a ``count()`` method
     597to count the number of objects they contain. Therefore, you can obtain a count
     598of all comments related to the current task with::
     599
     600    {{ task.comment_set.all.count }}
     601
     602And of course you can easily access methods you've explicitly defined on your
     603own models::
     604
     605    # In model
     606    class Task(models.Model):
     607        def foo(self):
     608            return "bar"
     609
     610    # In template
     611    {{ task.foo }}
     612
     613Because Django intentionally limits the amount of logic processing available
     614in the template language, it is not possible to pass arguments to method calls
     615accessed from within templates. Data should be calculated in views, then passed
     616to templates for display.
     617
    579618.. _template-built-in-reference:
    580619
    581620Using the built-in reference
Back to Top