133 | | Person.more_objects.get_list() |
| 132 | Person.people.get_list() |
| 133 | }}} |
| 134 | |
| 135 | == Multiple managers == |
| 136 | |
| 137 | '''Status: Done''' |
| 138 | |
| 139 | You can create as many managers as you want. When necessary (such as on the admin), Django will use the first one defined, in order. |
| 140 | |
| 141 | If you define at least one custom manager, it will not get the default "objects" manager. |
| 142 | |
| 143 | {{{ |
| 144 | #!python |
| 145 | class Person(models.Model): |
| 146 | first_name = models.CharField(maxlength=30) |
| 147 | last_name = models.CharField(maxlength=30) |
| 148 | people = models.Manager() |
| 149 | fun_people = SomeOtherManager() |
183 | | return super(PersonManager, self).get_list(self, **kwargs) # Call the "real" get_list() method. |
184 | | |
185 | | class Person(models.Model): |
186 | | first_name = models.CharField(maxlength=30) |
187 | | last_name = models.CharField(maxlength=30) |
188 | | class META: |
189 | | manager = PersonManager() |
| 199 | return models.Manager.get_list(self, **kwargs) # Call the "real" get_list() method. |
| 200 | |
| 201 | class Person(models.Model): |
| 202 | first_name = models.CharField(maxlength=30) |
| 203 | last_name = models.CharField(maxlength=30) |
| 204 | objects = PersonManager() |
| 205 | }}} |
| 206 | |
| 207 | == DoesNotExist exception renamed == |
| 208 | |
| 209 | '''Status: Done''' |
| 210 | |
| 211 | Instead of {{{people.PersonDoesNotExist}}}, it's not {{{Person.DoesNotExist}}}. |
| 212 | |
| 213 | Old: |
| 214 | {{{ |
| 215 | #!python |
| 216 | from django.models.myapp import people |
| 217 | try: |
| 218 | people.get_object(pk=1) |
| 219 | except people.PersonDoesNotExist: |
| 220 | print "Not there" |
| 221 | }}} |
| 222 | |
| 223 | New: |
| 224 | {{{ |
| 225 | #!python |
| 226 | from path.to.myapp import Person |
| 227 | try: |
| 228 | Person.objects.get_object(pk=1) |
| 229 | except Person.DoesNotExist: |
| 230 | print "Not there" |