Code

Changes between Initial Version and Version 7 of Ticket #8279


Ignore:
Timestamp:
08/28/08 22:41:18 (6 years ago)
Author:
mtredinnick
Comment:

(Fixed description formatting).

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #8279

    • Property Patch needs improvement unset
    • Property Needs tests unset
    • Property Milestone changed from to 1.0
    • Property Needs documentation unset
    • Property Triage Stage changed from Unreviewed to Accepted
  • Ticket #8279 – Description

    initial v7  
     1{{{ 
     2#!python 
    13class Entry(models.Model): 
    24    more_fields 
    35    related = models.ManyToManyField('self', verbose_name=_('related entries')) 
    46    translations = models.ManyToManyField('self', verbose_name=_('translations')) 
    5  
     7}}} 
    68 
    79From the database (postgres): 
    8  
     10{{{ 
    911blango=# select * from blango_entry_related; 
    1012 id | from_entry_id | to_entry_id  
     
    3032 
    3133blango=#  
    32  
     34}}} 
    3335 
    3436And from ./manage.py shell: 
     37{{{ 
    3538In [2]: from blango.models import *;Entry.objects.get(pk=27).related.all() 
    3639Out[2]: [] 
    3740In [3]: from blango.models import *;Entry.objects.get(pk=27).translations.all() 
    3841Out[3]: [] 
     42}}} 
    3943 
    4044The database query log indicates that Django is using the wrong table: 
     45{{{ 
    41462008-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}}} 
    4348 
    4449If I change the order of the m2m in the model to: 
    4550 
     51{{{ 
     52#!python 
    4653class Entry(models.Model): 
    4754   more_fields 
    4855   translations = models.ManyToManyField('self', verbose_name=_('translations')) 
    4956   related = models.ManyToManyField('self', verbose_name=_('related entries')) 
    50  
     57}}} 
    5158 
    5259Then I get all the related entries as related and as translations. 
    5360 
    5461If it serves as help, I've added a print statement in django/db/models/fields/related.py at line 776: 
    55  
     62{{{ 
    5663... 
    5764775         else: 
     
    5966777             return '%s_%s' % (opts.db_table, self.name) 
    6067... 
     68}}} 
    6169 
    6270Which prints: 
    6371 
     72{{{ 
    6473In [1]: from blango.models import *;Entry.objects.get(pk=27).related.all() 
    6574blango_entry_related 
     
    7180Out[2]: [] 
    7281 
     82}}}