78 | | In this case, item is a virtual field. |
| 78 | In this case, item is a virtual field. |
| 79 | |
| 80 | ==== Field options |
| 81 | There are 5 properties that each field can have: |
| 82 | |
| 83 | ===== Local |
| 84 | A local field is one that is defined on the queries model and is not derived from inheritance. |
| 85 | Fields from models that directly inherit from abstract models or proxy classes are still local |
| 86 | |
| 87 | {{{ |
| 88 | class Person(models.Model): |
| 89 | name = models.CharField(max_length=50) |
| 90 | |
| 91 | class Londoner(Person): |
| 92 | overdraft = models.DecimalField() |
| 93 | }}} |
| 94 | |
| 95 | Londoner has two fields (name and overdraft) but only one local field (overdraft) |
| 96 | |
| 97 | ===== Hidden |
| 98 | Hidden fields are only referred to related objects and related m2m. When a relational model (such as ManyToManyField, or ForeignKey) specifies a related_name that starts with a "+", it tells Django to not create a reverse relation. |
| 99 | {{{ |
| 100 | class City(models.Model): |
| 101 | name = models.CharField(max_length=100) |
| 102 | |
| 103 | class Person(models.Model): |
| 104 | city = models.ForeignKey(City, related_name='+') |
| 105 | }}} |
| 106 | |
| 107 | In this case, City has a related hidden object from Person (as you can't access person_set) |