Changes between Initial Version and Version 3 of Ticket #26092


Ignore:
Timestamp:
Jan 19, 2016, 7:08:56 PM (9 years ago)
Author:
Tim Graham
Comment:

Bisected to d43aa28f67c52bc6f5ea5868c711df263895713f

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #26092

    • Property Severity NormalRelease blocker
    • Property Triage Stage UnreviewedAccepted
  • Ticket #26092 – Description

    initial v3  
    88
    99{{{#!python
    10 from django.db import models
    11 
    12 
    1310class Person(models.Model):
    1411    name = models.CharField(max_length=200)
     
    1613
    1714class Publication(models.Model):
    18     title          = models.CharField(max_length=200)
    19     authors        = models.ManyToManyField(Person, through='Author')
    20 
    21     def get_authors(self):
    22         return self.authors.order_by('author_to_publication')
     15    title = models.CharField(max_length=200)
     16    authors = models.ManyToManyField(Person, through='Author')
    2317
    2418
    2519class Author(models.Model):
    26     person      = models.ForeignKey(Person, verbose_name='Author',
    27                                     related_name='author_to_publication')
    28     publication = models.ForeignKey(Publication, verbose_name='Publication')
    29     order_id    = models.PositiveSmallIntegerField(default=0)
     20    person = models.ForeignKey(Person, related_name='author_to_publication')
     21    publication = models.ForeignKey(Publication)
     22    order_id = models.PositiveSmallIntegerField(default=0)
    3023
    3124    class Meta:
     
    3326}}}
    3427
    35 And here is an example shell session which causes the problem
     28And here is an example test which causes the problem:
    3629
    37 {{{#!python
    38  % ./manage.py shell                                                                                                                                                                                                                                     [INS]
    39 Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
    40 [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    41 Type "help", "copyright", "credits" or "license" for more information.
    42 (InteractiveConsole)
    43 >>>
    44 >>> person = myapp.models.Person()
    45 >>> person.save()
    46 >>>
    47 >>> publication = myapp.models.Publication(title='test publication')
    48 >>> publication.save()
    49 >>> author = myapp.models.Author(person=person, publication=publication, order_id=1)
    50 >>> author.save()
    51 >>>
    52 >>> publication.authors.order_by('author_to_publication')
     30{{{#!python                                                                                                                                               
     31from django.test import TestCase
     32
     33from .models import Person, Publication, Author
     34
     35
     36class Test(TestCase):
     37    def test(self):
     38        person = Person()
     39        person.save()
     40        publication = Publication(title='test publication')
     41        publication.save()
     42        author = Author(person=person, publication=publication, order_id=1)
     43        author.save()
     44        list(publication.authors.order_by('author_to_publication'))
     45
    5346Traceback (most recent call last):
    5447  File "<console>", line 1, in <module>
     
    7265    if field.is_relation and path and opts.ordering and name != field.attname:
    7366AttributeError: 'ManyToOneRel' object has no attribute 'attname'
    74 >>>
    7567}}}
Back to Top