| 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) |
| 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 |
| | 31 | from django.test import TestCase |
| | 32 | |
| | 33 | from .models import Person, Publication, Author |
| | 34 | |
| | 35 | |
| | 36 | class 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 | |