Changes between Initial Version and Version 2 of Ticket #21763


Ignore:
Timestamp:
01/10/14 13:57:17 (14 months ago)
Author:
charettes
Comment:

I agree that raising a more significant AttributeError wouldn't hurt.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #21763

    • Property Patch needs improvement unset
    • Property Component changed from Uncategorized to Database layer (models, ORM)
    • Property Needs tests set
    • Property Version changed from 1.5 to master
    • Property Easy pickings set
    • Property Needs documentation unset
    • Property Type changed from Uncategorized to Cleanup/optimization
    • Property Triage Stage changed from Unreviewed to Accepted
  • Ticket #21763 – Description

    initial v2  
    1414
    1515Example:
    16     # in models.py
    17     from django.db import models
     16{{{
     17#!python
     18# in models.py
     19from django.db import models
    1820
    19     class Person(models.Model):
    20         pass
     21class Person(models.Model):
     22    pass
    2123
    22     class Group(models.Model):
    23         members = models.ManyToManyField(Person, through='Membership')
     24class Group(models.Model):
     25    members = models.ManyToManyField(Person, through='Membership')
    2426
    25     class Membership(models.Model):
    26         person = models.ForeignKey(Person)
    27         group = models.ForeignKey(Group)
    28         date_joined = models.DateField(auto_now_add=True)
     27class Membership(models.Model):
     28    person = models.ForeignKey(Person)
     29    group = models.ForeignKey(Group)
     30    date_joined = models.DateField(auto_now_add=True)
     31}}}
    2932
    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)
     39Traceback (most recent call last):
     40  File "<console>", line 1, in <module>
     41AttributeError: 'ManyRelatedManager' object has no attribute 'add'}}}
    4042
    4143[1] See, e.g., [this StackOverflow question](http://stackoverflow.com/q/8095813/2588818) and the related top comment/answer.
Back to Top