Ticket #1463: m2o-patch.diff
File m2o-patch.diff, 1.9 KB (added by , 19 years ago) |
---|
-
django/db/models/fields/related.py
115 115 except AttributeError: 116 116 val = getattr(instance, self.field.attname) 117 117 if val is None: 118 r aise self.field.rel.to.DoesNotExist118 return val 119 119 other_field = self.field.rel.get_related_field() 120 120 if other_field.rel: 121 121 params = {'%s__pk' % self.field.rel.field_name: val} -
tests/modeltests/m2o_recursive/models.py
31 31 >>> r.child_set.get(name__startswith='Child') 32 32 Child category 33 33 >>> r.parent 34 Traceback (most recent call last):35 ...36 DoesNotExist37 34 38 35 >>> c.child_set.all() 39 36 [] -
tests/modeltests/many_to_one_null/models.py
62 62 >>> a3.id 63 63 3 64 64 >>> a3.reporter 65 Traceback (most recent call last):66 ...67 DoesNotExist68 65 69 66 >>> a3 = Article.objects.get(pk=3) 70 67 >>> print a3.reporter.id 71 68 Traceback (most recent call last): 72 73 DoesNotExist 69 ... 70 AttributeError: 'NoneType' object has no attribute 'id' 74 71 75 # Accessing an article's 'reporter' attribute throws ReporterDoesNotExist76 # if the reporter isset to None.72 # Accessing an article's 'reporter' attribute returns None if the reporter is 73 # set to None. 77 74 >>> a3.reporter 78 Traceback (most recent call last):79 ...80 DoesNotExist81 75 82 76 # To retrieve the articles with no reporters set, use "reporter__isnull=True". 83 77 >>> Article.objects.filter(reporter__isnull=True)