Changes between Initial Version and Version 7 of Ticket #8279
- Timestamp:
- Aug 29, 2008, 12:41:18 AM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #8279
- Property Milestone → 1.0
- Property Triage Stage Unreviewed → Accepted
-
Ticket #8279 – Description
initial v7 1 {{{ 2 #!python 1 3 class Entry(models.Model): 2 4 more_fields 3 5 related = models.ManyToManyField('self', verbose_name=_('related entries')) 4 6 translations = models.ManyToManyField('self', verbose_name=_('translations')) 5 7 }}} 6 8 7 9 From the database (postgres): 8 10 {{{ 9 11 blango=# select * from blango_entry_related; 10 12 id | from_entry_id | to_entry_id … … 30 32 31 33 blango=# 32 34 }}} 33 35 34 36 And from ./manage.py shell: 37 {{{ 35 38 In [2]: from blango.models import *;Entry.objects.get(pk=27).related.all() 36 39 Out[2]: [] 37 40 In [3]: from blango.models import *;Entry.objects.get(pk=27).translations.all() 38 41 Out[3]: [] 42 }}} 39 43 40 44 The database query log indicates that Django is using the wrong table: 45 {{{ 41 46 2008-08-12 22:38:10 CEST LOG: statement: SELECT "blango_entry"."id", "blango_entry"."title", "blango_entry"."slug", "blango_entry"."author_id", "blango_entry"."language_id", "blango_entry"."body", "blango_entry"."body_html", "blango_entry"."pub_date", "blango_entry"."draft", "blango_entry"."allow_comments" FROM "blango_entry" INNER JOIN "blango_entry_translations" ON ("blango_entry"."id" = "blango_entry_translations"."to_entry_id") WHERE "blango_entry_translations"."from_entry_id" = 27 42 47 }}} 43 48 44 49 If I change the order of the m2m in the model to: 45 50 51 {{{ 52 #!python 46 53 class Entry(models.Model): 47 54 more_fields 48 55 translations = models.ManyToManyField('self', verbose_name=_('translations')) 49 56 related = models.ManyToManyField('self', verbose_name=_('related entries')) 50 57 }}} 51 58 52 59 Then I get all the related entries as related and as translations. 53 60 54 61 If it serves as help, I've added a print statement in django/db/models/fields/related.py at line 776: 55 62 {{{ 56 63 ... 57 64 775 else: … … 59 66 777 return '%s_%s' % (opts.db_table, self.name) 60 67 ... 68 }}} 61 69 62 70 Which prints: 63 71 72 {{{ 64 73 In [1]: from blango.models import *;Entry.objects.get(pk=27).related.all() 65 74 blango_entry_related … … 71 80 Out[2]: [] 72 81 82 }}}