Changes between Initial Version and Version 2 of Ticket #21763
- Timestamp:
- Jan 10, 2014, 1:57:17 PM (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #21763
- Property Component Uncategorized → Database layer (models, ORM)
- Property Easy pickings set
- Property Needs tests set
- Property Triage Stage Unreviewed → Accepted
- Property Type Uncategorized → Cleanup/optimization
- Property Version 1.5 → master
-
Ticket #21763 – Description
initial v2 14 14 15 15 Example: 16 # in models.py 17 from django.db import models 16 {{{ 17 #!python 18 # in models.py 19 from django.db import models 18 20 19 20 21 class Person(models.Model): 22 pass 21 23 22 23 24 class Group(models.Model): 25 members = models.ManyToManyField(Person, through='Membership') 24 26 25 class Membership(models.Model): 26 person = models.ForeignKey(Person) 27 group = models.ForeignKey(Group) 28 date_joined = models.DateField(auto_now_add=True) 27 class Membership(models.Model): 28 person = models.ForeignKey(Person) 29 group = models.ForeignKey(Group) 30 date_joined = models.DateField(auto_now_add=True) 31 }}} 29 32 30 ... 31 # on shell 32 >>> from testing.models import * 33 >>> group = Group.objects.create() 34 >>> person = Person.objects.create() 35 >>> group.members.add(person) 36 Traceback (most recent call last): 37 File "<console>", line 1, in <module> 38 AttributeError: 'ManyRelatedManager' object has no attribute 'add' 39 33 {{{ 34 # on shell 35 >>> from testing.models import * 36 >>> group = Group.objects.create() 37 >>> person = Person.objects.create() 38 >>> group.members.add(person) 39 Traceback (most recent call last): 40 File "<console>", line 1, in <module> 41 AttributeError: 'ManyRelatedManager' object has no attribute 'add'}}} 40 42 41 43 [1] See, e.g., [this StackOverflow question](http://stackoverflow.com/q/8095813/2588818) and the related top comment/answer.