django-mptt

Django mptt, extends “base.html”

为君一笑 提交于 2021-02-10 07:49:09
问题 In base.html: <div id="menu_shop"> <input name="search" placeholder="search"> <p>Category:</p> {% load mptt_tags %} <ul class="root"> {% recursetree nodes %} <li> {{ node.name }} {% if not node.is_leaf_node %} <ul class="children"> {{ children }} </ul> {% endif %} </li> {% endrecursetree %} </ul> </div> in views: def show_category_tree(request): return render_to_response("base.html", {'nodes': Category.tree.all()}, context_instance=RequestContext(request)) urls.py: url(r'^category/', 'item

Annotate Total Count of Descents of Mptt Model

為{幸葍}努か 提交于 2021-01-04 06:41:05
问题 Question Given the models below, I want to get a queryset of all pages, annotated with the total number of comments in the thread associated to the page, including all comments in a comment thread tree associated with pages. I am using django-mptt to store comment tree. I can get this in python using comment.get_descendant_count() , but this is very ineficient when querying all pages Models class CommentThread(models.Model): ... class Page(models.Model): ... thread = models.ForeignKey(

Is it possible to integrate django-taggit and django-mptt / django-treebeard?

£可爱£侵袭症+ 提交于 2020-01-13 11:15:30
问题 I am developing a website that requires tagging up different types of content, which favors using django-taggit. But, it would be extremely beneficial if the tags were represented in the database in their natural hierarchy, favoring use of django-mptt or django-treebeard. What is the best solution to integrate the generic tagging functionality of taggit with the tree-structure provided by mptt / treebeard? 回答1: I used treebeard and taggit's custom through models to implement hierarchical tags

Is it possible to integrate django-taggit and django-mptt / django-treebeard?

随声附和 提交于 2020-01-13 11:15:19
问题 I am developing a website that requires tagging up different types of content, which favors using django-taggit. But, it would be extremely beneficial if the tags were represented in the database in their natural hierarchy, favoring use of django-mptt or django-treebeard. What is the best solution to integrate the generic tagging functionality of taggit with the tree-structure provided by mptt / treebeard? 回答1: I used treebeard and taggit's custom through models to implement hierarchical tags

Upgrading from Django 1.7.1 to 1.8.2 fails

江枫思渺然 提交于 2020-01-11 12:54:09
问题 My Django 1.7.1 application runs fine. But I would like to upgrade to the more recent version 1.8.2. I'm following the instructions here which basically just say to do pip install -U Django from within my VirtualEnvironment. After I do that line though, I Immediately try to do manage.py and it fails as shown below. Can someone suggest to me what I should do to fix this? The errors below look like they have something to do with the MPTT module. (I'm running version 0.6.1 of MPTT). Upgrading to

Django MPTT - how to query based on URL segments

狂风中的少年 提交于 2020-01-05 11:49:28
问题 I have: Home Things with Fur Dog Horse Basket Ball Games Twenty One Horse Assuming the slug for each is title.lower().replace(' ', '-') , my URLs would be: /home/ /home/things-with-fur/ /home/things-with-fur/dog/ /home/things-with-fur/horse/ /home/basket-ball-games/ /home/basket-ball-games/twenty-one/ /home/basket-ball-games/horse/ The slug field is unique_together with the parent . I need to, based on the URL segements, query for the correct category. I can't simply query for the basket ball

django-mptt ImportError

我只是一个虾纸丫 提交于 2019-12-24 03:04:49
问题 I have installed django-mptt and have followed the documentation regarding setting up a Django model for MPTT However, I am getting the following ImportError: from mptt.models import MPTTModel, TreeForeignKey ImportError: cannot import name TreeForeignKey Can anyone help? Any advice appreciated. Thanks. 回答1: TreeForeignKey is a class defined in the file fields.py. It looks like this file was just recently added to the code base for v0.5.pre. If you are using version 0.4.2 or older, this file

efficient function to retrieve a queryset of ancestors of an mptt queryset

a 夏天 提交于 2019-12-21 03:32:36
问题 Does anybody have an efficient algorithm to retrieve all ancestors of an mptt queryset? The best I could think of so far is something like this: def qs_ancestors(queryset): if isinstance(queryset, EmptyQuerySet): return queryset queryset_aggs = queryset.values_list('tree_id', 'level').annotate(max_lft=Max('lft'), min_rght=Min('rght')) new_queryset = queryset.none() for tree_id, level, max_lft, min_rght in queryset_aggs: ancestors = MyModel.objects.filter( tree_id=tree_id, level__lt=level, lft

How to serialize hierarchical relationship in Django REST

大憨熊 提交于 2019-12-21 00:00:12
问题 I have a Django model that is hierarchical using django-mptt, which looks like: class UOMCategory(MPTTModel, BaseModel): """ This represents categories of different unit of measurements. """ name = models.CharField(max_length=50, unique=True) description = models.CharField(max_length=50, unique=True) parent = TreeForeignKey('self', null=True, blank=True, related_name='%(app_label)s_%(class)s_sub_uom_categories') The problem now is I created a REST API using Django REST Framework; how do I

Trouble using django-mptt for nested comment system

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 03:59:42
问题 I'm trying to set up a simple nested comment system using django-mptt, but I'm running into a few issues. If someone could take a look and tell me what I'm doing wrong, I would be really grateful. So far, I've only set up the display of comments for a particular post; any creating/updating/deleting is for the time being happening through the admin. One of the issues I'm having is that sometimes when I try to create/update/delete in the admin, I get the Attribute Error "'NoneType' object has