Changes between Initial Version and Version 2 of Ticket #21763


Ignore:
Timestamp:
Jan 10, 2014, 1:57:17 PM (11 years ago)
Author:
Simon Charette
Comment:

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

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #21763

    • Property Component UncategorizedDatabase layer (models, ORM)
    • Property Easy pickings set
    • Property Needs tests set
    • Property Triage Stage UnreviewedAccepted
    • Property Type UncategorizedCleanup/optimization
    • Property Version 1.5master
  • 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