-
Book Overview & Buying
-
Table Of Contents
Mastering Django: Core
By :
When you define a relationship in a model (that is, a ForeignKey, OneToOneField, or ManyToManyField), instances of that model will have a convenient API to access the related object(s).
Using the models at the top of this page, for example, an Entry object e can get its associated Blog object by accessing the blog attribute: e.blog.
(Behind the scenes, this functionality is implemented by Python descriptors. This shouldn't really matter to you, but I point it out here for the curious.)
Django also creates API accessors for the other side of the relationship-the link from the related model to the model that defines the relationship. For example, a Blog object b has access to a list of all related Entry objects via the entry_set attribute: b.entry_set.all().
All examples in this section use the sample Blog, Author and Entry models defined at the top of this page.
If a model has a ForeignKey, instances of that model will have access to the related...
Change the font size
Change margin width
Change background colour