mbraak / django-mptt-admin Goto Github PK
View Code? Open in Web Editor NEWDjango-mptt-admin provides a nice Django Admin interface for Mptt models
Home Page: https://mbraak.github.io/django-mptt-admin/
License: Other
Django-mptt-admin provides a nice Django Admin interface for Mptt models
Home Page: https://mbraak.github.io/django-mptt-admin/
License: Other
I keep getting this error in the change list view:
Uncaught TypeError: $tree.tree is not a function
I followed the README and compared with the example projects. I can see no mistake. The scripts seem to load fine, the jQuery('#tree')
result seems fine, but it has no tree()
method. What could be going on here? I tred v.0.3.3 (c352ec0) as well as master but to no avail (except in master the error looks a bit different due to minifcation).
Django-mptt-admin shows an empty tree if the ids are uuids and the database is Postgresql.
It does seem to work for Mysql and Sqlite. The difference is probably that Postgresql uses native uuids.
Django has changed the support for its versions:
The development version of django-mptt-admin drops support for Django 1.6 and older. Note that the latest stable version supports Django 1.4 - 1.8.
Hi,
First of all thanks to you guys.
i am using django mptt admin and its working fine for me. but, there is a problem in tree admin view.
i want to display selected records in tree view, for this i have override "def queryset(self, request)" in admin view, filtered records are coming is grid view but tree view still displaying all records. please find the code below.
def queryset(self, request):
qs = super(EmpAdmin, self).queryset(request)
return qs.filter(dept__id=10)
so only those records should be displayed in tree format in which dept_id is 10, but its displaying all records.
I have a custom queryset in admin.py to hide records based on an internal "deleted" field:
def queryset(self, request): qs = super(BillArchiveDocumentAdmin, self).queryset(request) return qs.filter(deleted=False)
This works fine in Grid view but not in Tree view - all records are displayed.
As far as I can tell, the admin.py queryset is not called by django-mptt-admin.
I got a trace after upgrading django-mptt-admin from 0.3.3 to 0.3.4 on manage.py collectstatic
:
Post-processing 'django_mptt_admin/django_mptt_admin.css' failed!
ValueError: The file 'django_mptt_admin/jqtree-circle.png' could not be found with <django.contrib.staticfiles.storage.CachedStaticFilesStorage object
It seems the jqtree-circle.png
is missed.
tree_auto_open doesn't seem to work, it always only open nodes lvl 1. Any idea how to open all nodes?
Dear Marco,
First of all thank you for django-mptt-admin. I'm new to django, so
perhaps I missed something that it is basic but I did not understand
how to do achieve what I want.
I would like to have a tree also when user have to select the Node for
TreeForeignField. I've look at the django-mptt-admin's documentation
but I didn't found it.
Is it feasible?
if yes which is the right way to do it with django-mptt-admin?
If no, perhaps you can suggest the right direction to implement this
functionality.
I've created a simple models.py like:
{{{
from django.db import models
from mptt.models import MPTTModel, TreeForeignKey
class Nuts(MPTTModel):
name = models.CharField(max_length=20, unique=True, db_index=True)
label = models.CharField(max_length=100)
parent = TreeForeignKey('self', null=True, blank=True,
related_name='children', db_index=True)
class MPTTMeta:
order_insertion_by = ['name']
def str(self):
return self.name + ' - ' + self.label
class Data(models.Model):
name = models.CharField(max_length=20, unique=False, db_index=False)
nuts = TreeForeignKey(Nuts, null=True, blank=True,
related_name='fk_nuts', db_index=True)
}}}
in the admin file I wrote:
{{{
from django.contrib import admin
from django_mptt_admin.admin import DjangoMpttAdmin
from nuts.models import Nuts, Data
class NutsAdmin(DjangoMpttAdmin):
tree_auto_open = 0
tree_load_on_demand = True
admin.site.register(Nuts, DjangoMpttAdmin)
admin.site.register(Data, DjangoMpttAdmin)
}}}
Any hint?
Best regards
Pietro
If you right click on the tree, nothing happens. The default browser menu should appear.
Hi,
I have a "custom" django admin site, which is instantiate as below:
class UserAdmin(AdminSite):
login_form = AuthenticationForm
def has_permission(self, request):
return request.user.is_active
manage = UserAdmin(name='manage')
and my urls.py as:
...
(r'^manage/', include(manage.urls)),
...
Then when i tried to do "add" action, the url resolved '/admin/' instead of '/manage/'
But, in the "grid view" it resolved correctly ('/manage/')
Please see attachment to see clearly what i meant:
I've tried debugging and find my self no answer how to resolve the "add" url correctly
Upgrade to 2.1.0 and 1.11.0
Hi,
First thanks for this great lib, works like a charm and so easy to install (using it with django-suit)
My tree list have in the grid view some custom actions (to activate one or much element in the list), and I can't figure to do without that. Do you think it's difficult to implemented some checkboxes and related actions to the tree view ?
I'll be ok to help with that if I can have some help to begin =)
Thks in advance !
I use a uuid for the primary key instead of an int. It seems that this causes moving a node to fail
(Here was an issue with callabes in list_display. However, it doesn't belong to mptt-admin and being caused by django-mptt itself. I apologize for creating a ticket in here, and feel free to close it)
When in grid view, the individual links to the object pages are incorrect.
Right now they are:
/admin/app_name/model_name/grid/object_id
when they should be:
/admin/app_name/model_name/object_id
Some admin skins already include jQuery; having the changelist_view include it itself will often break or, at best, be an unnecessary inclusion.
Would it be possible to add a settings variable for this, so configurators can choose not to have you include your own private jQuery?
Do not use inline javascript so we can use 'Content security policy' settings
I have a mptt model with SlugField
# @python_2_unicode_compatible
class Category(MPTTModel):
name = models.CharField(
max_length=255)
slug = models.SlugField()
parent = TreeForeignKey(
to='self',
related_name='children',
null=True, blank=True,
db_index=True)
class Meta:
unique_together = [
('parent', 'name')
]
class MPTTMeta:
order_insertion_by = ['name']
def __str__(self):
return '{}'.format(self.name)
and DjangoMpttAdmin admin with a prepopulated field.
class CategoryAdmin(DjangoMpttAdmin):
prepopulated_fields = {"slug": ("name",)}
Then I open /admin/app/category/add page, the slug field prepopulation doesn't work. I see an error message in the Javascript console:
Uncaught TypeError: $ is not a function
Django embeds a couple of scripts on the admin form page:
(function($) {
...
})(django.jQuery);
but django.jQuery doesn't defined beacuse jquery.init.js doesn't included into the page.
I tried to fix this with workaround:
class CategoryAdmin(DjangoMpttAdmin):
prepopulated_fields = {"slug": ("name",)}
@property
def media(self):
media = super(DjangoMpttAdmin, self).media
extra = '' if settings.DEBUG else '.min'
js = [
'core.js',
'vendor/jquery/jquery%s.js' % extra,
'jquery.init.js',
'admin/RelatedObjectLookups.js',
'actions%s.js' % extra,
'urlify.js',
'prepopulate%s.js' % extra,
'vendor/xregexp/xregexp.min.js',
]
media.add_js(['admin/js/%s' % url for url in js])
return media
( https://github.com/django/django/blob/master/django/contrib/admin/options.py#L568-L577 )
But then I got the Uncaught TypeError: jQuery is not a function
from the django_mptt_admin.js
because jquery.init.js
install jQuery with a noconflict
mode.
I think, standard Django Admin scripts should be included anyway because they are used in the standard field widgets.
If django_mptt_admin.js uses jQuery from Django Admin, it should call it as django.jQuery
, not jQuery
.
With a model such as:
class Product_Line(MPTTModel):
product_line = models.CharField(max_length=40, null=False, help_text='Product code')
# ...
parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)
class Meta:
ordering = ['product_line', 'short_description']
verbose_name_plural = u"Product lines"
verbose_name = u'Product line'
class MPTTMeta:
order_insertion_by = ['short_description']
django-mptt-admin fails when fetching data for an admin changelist. This only happens once instances are created beyond the root level.
Full traceback:
Internal Server Error: /admin/part_numbers/product_line/tree_json/ Traceback (most recent call last): File "/home/ian/.virtualenvs/THERMALINE/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/ian/.virtualenvs/THERMALINE/local/lib/python2.7/site-packages/django_mptt_admin/admin.py", line 73, in wrapper return self.admin_site.admin_view(view)(*args, **kwargs) File "/home/ian/.virtualenvs/THERMALINE/local/lib/python2.7/site-packages/django/utils/decorators.py", line 110, in _wrapped_view response = view_func(request, *args, **kwargs) File "/home/ian/.virtualenvs/THERMALINE/local/lib/python2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func response = view_func(request, *args, **kwargs) File "/home/ian/.virtualenvs/THERMALINE/local/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 233, in inner return view(request, *args, **kwargs) File "/home/ian/.virtualenvs/THERMALINE/local/lib/python2.7/site-packages/django_mptt_admin/admin.py", line 193, in tree_json_view tree_data = self.get_tree_data(qs, max_level) File "/home/ian/.virtualenvs/THERMALINE/local/lib/python2.7/site-packages/django_mptt_admin/admin.py", line 173, in get_tree_data return util.get_tree_from_queryset(qs, handle_create_node, max_level) File "/home/ian/.virtualenvs/THERMALINE/local/lib/python2.7/site-packages/django_mptt_admin/util.py", line 57, in get_tree_from_queryset parent_id = getattr(instance.parent, pk_attname) AttributeError: 'NoneType' object has no attribute 'id'
I have different types of models that will be combined in one tree. But the admin does not seem to understand...
Here are my models:
class Structure(MPTTModel):
title = models.CharField(max_length=255)
parent = TreeForeignKey('self', null=True, blank=True, related_name='structures', db_index=True)
def __str__(self):
return self.title
class StructureArticleItem(MPTTModel):
article = models.ForeignKey(Article)
presentation = models.IntegerField(choices=STRUCTURE_ARTICLE_PRESENTATION, default=1)
parent = TreeForeignKey(Structure, null=True, blank=True, related_name='article_items', db_index=True)
def __str__(self):
return self.article.title
class StructureWebItem(MPTTModel):
url = models.URLField()
parent = TreeForeignKey(Structure, null=True, blank=True, related_name='web_items', db_index=True)
Is this a missing feature, or is it not able to find the missing models?
pip install django-mptt-admin
instead of pip install django_mptt_admin
in continuation of this discussion.
I use https://github.com/leukeleu/django-mptt-admin
It uses dynamic loading data by URL and saveState by jq cookie, but when I reload the page tree is reset. I think this is due to dynamic loading with AJAX. How can I solve this problem?
I don't have that many items and so I'd like it to be expanded by default.
Is there an easy way to do that?
Thanks, this worked right out of the box!
I have something like below. Using django-parler, mptt
class Menu(MPTTModel, TranslatableModel):
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
translations = TranslatedFields(
title = models.CharField(_('title'), max_length=255, unique=True),
slug = models.UnicodeSlugField(_('slug'), unique=True),
hint = models.CharField(_('hint'), max_length=255, null=True, blank=True),
)
I can get the entire trees as below
<ul>
{% recursetree page_list %}
<li>
<a href="{{ node.get_absolute_url }}">{{ node.title }}</a>
{% if not node.is_leaf_node %}
<ul>
{{ children }}
</ul>
{% endif %}
</li>
{% endrecursetree %}
</ul>
Now how do I get 'sibling & child' trees? What I am trying to do is to have a small menu app, using django-mptt-admin. Thus, in a situation like below
Home
Company
- History
- Background
- Location Map
If I am at 'background', I wish to display 'history, background, location map' in the side menu - and display the root page 'Company' page as well.
Any example?
Moving a node fails for some reason. I think django-mptt-admin should display an error message.
Setting the option tree_load_on_demand to False should disable load on demand.
Hi,
I am applying django-mptt-admin on a table which is already exists and have so many records in it already.
Problem with django-mptt-admin is you have to create parent first then children.
In my case i have already created children and now i have created parent, in this case children will not come under their parents.
For Example :
row id 1,2,3,4 and 5 is children and row id 6 is parent
when i am assinging parent to children , its not coming in tree.
In the version 0.1.5. removing a node in the tree view, by clicking edit and then removing it in the detail view causes a JavaScript error. The node is selected and then removed, which causes a JavaScript call to a node which doesn't exist any more.
Here is an example:
/admin/app/model/tree_json/?selected_node=1&_=1378719550852
In this case i removed the node with id 1 and it became the selected node in the tree view by clicking the edit link. Then it was removed. Back in the tree view the tree rendering crashes, because the JavaScript call returns HTTP500, ObjectDoesNotExist.
I downgraded to 0.1.4 to avoid this. Please request more information on this if needed, I'm willing to participate solving this issue.
Hello,
Cool product. Curious, is it possible to get the jQuery object that django-mptt-admin is using, and bind events to that? I haven't been able to work it out myself yet.
I'm using Django and Django Grappelli, and in the admin, Grappelli puts jQuery on both a django and a grp variable, to make them accessible like this: django.jQuery and grp.jQuery. It then calls $.noConflict(true) which basically removes all global references to those jQuery instances.
At this point, django-mptt-admin, starts up fine, with its copy of jQuery. However, when I try to add an event to the jqTree like this
(function($) {
$(document).ready(function() {
$tree.bind(
'tree.select',
function(event) {
if (event.node) {
console.log(event.node.name+" was selected.");
} else {
console.log(event.previous_node + " was deselected.");
}
});
});
})(<which jQuery?>);
I can't use grp.jQuery or django.jQuery, since the custom events like tree.select aren't defined on those jQuerys. It seems also that no jQuery exists. Is there a way to get the jQuery from django-mptt-admin to use here?
I'm not too strong with JavaScript, so the solution might be simple. Here some ideas I have
In any case, thanks for the project, it's very helpful.
Gene
Collapse is NOT collapsed.
Seems below js
<script type="text/javascript" src="/static/django_mptt_admin/jquery_namespace.js"></script>
<script type="text/javascript" src="/static/django_mptt_admin/django_mptt_admin.js"></script>
Conflicts with django admin change detail page, collapse feature. HTML source is as below. It is NOT collaped.
<fieldset class="module aligned collapse">
<h2>Image Title & Layout Option</h2>
<div class="form-row field-image_title">
Admin.py related scripts are
(_('Image Title & Layout Option'), {
'classes': ('collapse',),
'fields': ('image_title','image_sub_title','image_column_type'),
}),
Anywork around?
The new block-style layout does not look correct for rtl languages
It's impossible to move a node to the first position of the tree.
Marco,
The 0.3.4 version requires jQuery.cookie but doesn't include it.
Edge : SCRIPT438: Object doesn't support property or method 'cookie'
django_mptt_admin.js (1,970)
Firefox : TypeError: jQuery.cookie is not a function
django_mptt_admin.js:1:976
The 0.3.3 version works perfectly.
Kr
Patrick
Django 1.7 alpha is out
mptt.admin.MPTTModelAdmin. This is a bare-bones tree admin. All it does ... and indent the nodes in the tree to make a pretty tree list view...
DjangoMpttAdmin does no indentation in the grid view even when setting mptt_level_indent.
Let's not include our own own version of jquery, but use the version of the django admin.
A lot easier than hosting a demo :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.