django-mptt

How can create a json tree from django-mptt?

喜欢而已 提交于 2019-11-29 03:05:35
问题 I want to use the JavaScript InfoVis Tooljit ( http://thejit.org ) to render a tree of mptt nodes in django. How can i create the required json structure (see http://thejit.org/static/v20/Jit/Examples/Spacetree/example1.code.html for an example) in django? Thanks 回答1: If you use the template functionality of django-mptt to generate the JSON data you should be able to do something like the following: var json = {% recursetree nodes %} { id: "{{ node.id }}", name: "{{ node.name }}", data: {},

How do I rebuild my django-mptt tree?

十年热恋 提交于 2019-11-28 22:48:42
问题 I'm using django-mptt 0.4.2, and want to rebuild a tree. The tree manager has a method rebuild() which I try to access like this: >>> my_rootnode = MyObj.objects.get(id=12) >>> my_rootnode.tree.rebuild() Traceback (most recent call last): File "<console>", line 1, in <module> File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 211, in __get__ raise AttributeError("Manager isn't accessible via %s instances" % type.__name__) AttributeError: Manager isn't accessible

Django - How to get self.id when saving a new object?

人走茶凉 提交于 2019-11-28 09:37:49
I have a problem in one of my models. I'm uploading an image, and I want to store the id (pk in the database table) but I need to know at which point Django will have access to self.id . models.py class BicycleAdItemKind(MPTTModel): def url(self, filename): pdb.set_trace() url = "MultimediaData/HelpAdImages/ItemKind/%s/%s" % (self.id, filename) return url def item_kind_image(self): return '<img align="middle" src="/media/%s" height="60px" />' % self.image item_kind_image.allow_tags = True # Bicicleta completa, Componentes para bicicleta, Acessorios para ciclista n_item_kind = models.CharField

Django - How to get self.id when saving a new object?

拈花ヽ惹草 提交于 2019-11-27 03:03:19
问题 I have a problem in one of my models. I'm uploading an image, and I want to store the id (pk in the database table) but I need to know at which point Django will have access to self.id . models.py class BicycleAdItemKind(MPTTModel): def url(self, filename): pdb.set_trace() url = "MultimediaData/HelpAdImages/ItemKind/%s/%s" % (self.id, filename) return url def item_kind_image(self): return '<img align="middle" src="/media/%s" height="60px" />' % self.image item_kind_image.allow_tags = True #