Giter Site home page Giter Site logo

mbraak / django-mptt-admin Goto Github PK

View Code? Open in Web Editor NEW
293.0 293.0 46.0 5.94 MB

Django-mptt-admin provides a nice Django Admin interface for Mptt models

Home Page: https://mbraak.github.io/django-mptt-admin/

License: Other

JavaScript 2.42% HTML 3.18% Python 76.69% TypeScript 13.47% SCSS 4.24%
django django-admin django-mptt-admin mptt-models

django-mptt-admin's People

Contributors

andrewdodd avatar andrkhr avatar arjunattam avatar bitdeli-chef avatar changesomecode avatar christianwgd avatar deejaypee avatar dependabot[bot] avatar hstanev avatar igorgai avatar jdzero avatar jmsoler7 avatar maxperreault avatar mbraak avatar nanuuki avatar nnseva avatar nonzero avatar pawel-ch avatar pevar avatar quantifiedcode-bot avatar requires avatar roodie avatar tagmat avatar tomkins avatar uralbash avatar xrmx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-mptt-admin's Issues

django-mptt-admin: get expandable tree also for TreeForeignKey

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

Drop support for Django 1.6 and older

Django has changed the support for its versions:

  • Django 1.4 will be supported until october 2015
  • Other versions <= 1.6 will not be supported

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.

$tree.tree is not a function

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).

Admin Override queryset not working

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.

Display filtered records in admin

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.

Expanded by default?

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!

Is binding event handlers supported?

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

  1. Do something you guys recommend
  2. Clone the project, create a patch to somehow export the jQuery, or provide a jQuery to use, use that, give back to you guys for review.
  3. Clone the project, and add support for responding to the events I need right in the source, not sure the right way to do that yet, though.

In any case, thanks for the project, it's very helpful.

Gene

Attempt to read pk of parent of root instance causes error

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'

when using custom admin site, "add" url is not resolved properly

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
screen shot 2015-01-26 at 11 08 14 pm

0.3.4: failure on collectstatic (jqtree-circle.png)

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.

TypeError: jQuery.cookie is not a function

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

Other models get not listed in tree

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?

Add actions on tree view

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 !

Removing node from the tree causes the tree view to crash.

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.

Templatetags for top children menu...

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?

Django Admin scripts don't included in the admin form

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.

Support for uuid ids

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.

Tree Structure not coming properly

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.

Make inclusion of jQuery optional; might be a duplicate

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?

Change detail page collapse issue

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 &amp; 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?

mptt_level_indent ignored in grid view

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.

list_display misbehaves / is broken

(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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.