Changeset 7762
- Timestamp:
- 06/26/08 02:04:18 (3 months ago)
- Files:
-
- django/trunk/AUTHORS (modified) (1 diff)
- django/trunk/django/db/models/fields/related.py (modified) (3 diffs)
- django/trunk/tests/modeltests/model_inheritance/models.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/AUTHORS
r7693 r7762 377 377 Filip Wasilewski <filip.wasilewski@gmail.com> 378 378 Dan Watson <http://theidioteque.net/> 379 Joel Watts <joel@joelwatts.com> 379 380 Chris Wesseling <Chris.Wesseling@cwi.nl> 380 381 James Wheare <django@sparemint.com> django/trunk/django/db/models/fields/related.py
r7622 r7762 104 104 if hasattr(sup, 'contribute_to_class'): 105 105 sup.contribute_to_class(cls, name) 106 107 if not cls._meta.abstract and self.rel.related_name: 108 self.rel.related_name = self.rel.related_name % {'class': cls.__name__.lower()} 109 106 110 other = self.rel.to 107 111 if isinstance(other, basestring): … … 109 113 else: 110 114 self.do_related_class(other, cls) 111 if not cls._meta.abstract and self.rel.related_name:112 self.rel.related_name = self.rel.related_name % {'class': cls.__name__.lower()}113 115 114 116 def set_attributes_from_rel(self): … … 120 122 self.set_attributes_from_rel() 121 123 related = RelatedObject(other, cls, self) 122 self.contribute_to_related_class(other, related) 124 if not cls._meta.abstract: 125 self.contribute_to_related_class(other, related) 123 126 124 127 def get_db_prep_lookup(self, lookup_type, value): django/trunk/tests/modeltests/model_inheritance/models.py
r7600 r7762 38 38 class Meta: 39 39 pass 40 41 # 42 # Abstract base classes with related models 43 # 44 45 class Post(models.Model): 46 title = models.CharField(max_length=50) 47 48 class Attachment(models.Model): 49 post = models.ForeignKey(Post, related_name='attached_%(class)s_set') 50 content = models.TextField() 51 52 class Meta: 53 abstract = True 54 55 def __unicode__(self): 56 return self.content 57 58 class Comment(Attachment): 59 is_spam = models.BooleanField() 60 61 class Link(Attachment): 62 url = models.URLField() 40 63 41 64 # … … 129 152 AttributeError: type object 'CommonInfo' has no attribute 'objects' 130 153 131 # The Place/Restaurant/ItalianRestaurant models, on the other hand, all exist 132 # as independent models. However, the subclasses also have transparent access 133 # to the fields of their ancestors. 154 # Create a Post 155 >>> post = Post(title='Lorem Ipsum') 156 >>> post.save() 157 158 # The Post model has distinct accessors for the Comment and Link models. 159 >>> post.attached_comment_set.create(content='Save $ on V1agr@', is_spam=True) 160 <Comment: Save $ on V1agr@> 161 >>> post.attached_link_set.create(content='The Web framework for perfectionists with deadlines.', url='http://www.djangoproject.com/') 162 <Link: The Web framework for perfectionists with deadlines.> 163 164 # The Post model doesn't have an attribute called 'attached_%(class)s_set'. 165 >>> getattr(post, 'attached_%(class)s_set') 166 Traceback (most recent call last): 167 ... 168 AttributeError: 'Post' object has no attribute 'attached_%(class)s_set' 169 170 # The Place/Restaurant/ItalianRestaurant models all exist as independent 171 # models. However, the subclasses also have transparent access to the fields of 172 # their ancestors. 134 173 135 174 # Create a couple of Places.
