スポンサーサイト
一定期間更新がないため広告を表示しています
- 2014.12.23 Tuesday
- -
- -
- -
- -
- -
- by スポンサードリンク
I'm not sure where everyone is on this but I figured it out for me so I thought I'd share:
The problem is that the get_all_related_many_to_many_objects() caches itself, so if the many-to-many manager gets called before all the apps are loaded, any models in apps added afterwards won't be in that cache. I commented out the line that gets the cache so it has to re-cache each time, and it fixes the problem. Behold:
def get_all_related_many_to_many_objects(self):
try: # Try the cache first.
return self.ham_sandwich
#return self._all_related_many_to_many_objects
except AttributeError:
...
Since .ham_sandwich is never found it falls into the AttributeError? exception and re-caches. It then works as planned.
The permanent fix, it seems to me, is to make it so that when a many-to-many is created, it clears the _all_related_many_to_many_objects of the _meta of the relation class, but I'm not sure exactly where best to do that.
from other_app.models import Tag
class Thing(models.Model):
tag = models.ManyToManyField(Tag)
del Tag._meta._all_related_many_to_many_objects
def entry(request, object_id):
object = Entry.objects.get(id=object_id)
##tags = object.tags.all()
tags = Tag.objects.extra(tables = ['myapp_entry_tags'],
where=['myapp_entry_tags.tag_id = myapp_tag.id ¥
AND myapp_entry_tags.entry_id=%s'],
params=[object.id])
return render_to_response("myapp/entry_detail.html",
{ 'object':object, 'tags':tags },
context_instance=RequestContext(request))
<input type="checkbox" name="test" value="hoge" checked="checked" />
<input type="checkbox" name="test" value="hage" checked="checked" />
<input type="checkbox" name="test" value="mage" checked="checked" />
<input type="checkbox" name="test[]" value="hoge" checked="checked" />
<input type="checkbox" name="test[]" value="hage" checked="checked" />
<input type="checkbox" name="test[]" value="mage" checked="checked" />
<input type="checkbox" name="test[0]" value="hoge" checked="checked" />
<input type="checkbox" name="test[1]" value="hage" checked="checked" />
<input type="checkbox" name="test[2]" value="mage" checked="checked" />
# coding: utf8
from django import template
register = template.Library()
@register.filter()
def sjis(value):
return unicode(value,'utf8').encode('sjis')
このエントリーに関連付けられたタグ:
{% for tag in object.tag.all %}
{{ tag.name }}
{% endfor %}
e=Entry.objects.get(pk=1)
for tag in e.tag.all():
tag.name
tar -zxvf httpd-2.0.55.tar.gz
./configure --enable-so --enable-mods-shared=all --with-layout=RedHat
make
make install
#(あれこれ出したり入れたりしてたので最初からルートで作業してます^^;)