idlesign / django-sitetree

Reusable application for Django introducing site tree, menu and breadcrumbs navigation elements.
http://github.com/idlesign/django-sitetree
BSD 3-Clause "New" or "Revised" License
347 stars 132 forks source link

NoReverseMatch on custom models #293

Closed iwalucas closed 3 years ago

iwalucas commented 3 years ago

I have a custom model for TreeBase and TreeItem, but when I try to add a new tree item, I got a NoReverseMatch error.

models.py :

class CustomTreeItem(TreeItemBase):
    content_reference_type = models.CharField(max_length=2,choices=CREF_TYPES,default='IN')

class PortalTree(TreeBase):
    customer = models.ForeignKey(
        Customer,
        on_delete=models.CASCADE, 
    )

Error:

Reverse for 'portal_portaltree_changelist' not found. 'portal_portaltree_changelist' is not a valid view function or pattern name.

It fails here (breadcrumbs.html): <a href="{% url tree.urls.changelist %}">{{ tree.verbose_name_plural }}</a>

admin.py


from sitetree.admin import TreeItemAdmin, TreeAdmin, override_tree_admin, override_item_admin
class CustomTreeItemAdmin(TreeItemAdmin):
    fieldsets = (
            (_('Basic settings'), {
                'fields': ('parent', 'title', 'url','content_reference_type',)
            }),
            (_('Access settings'), {
                'classes': ('collapse',),
                'fields': ('access_loggedin', 'access_guest', 'access_restricted', 'access_permissions', 'access_perm_type')
            }),
            (_('Display settings'), {
                'classes': ('collapse',),
                'fields': ('hidden', 'inmenu', 'inbreadcrumbs', 'insitetree')
            }),
            (_('Additional settings'), {
                'classes': ('collapse',),
                'fields': ('hint', 'description', 'alias', 'urlaspattern')
            }),
        )
class PortalTreeAdmin(TreeAdmin):
    list_filter = ['customer',]
    list_display =['customer','title','alias',]

override_item_admin(CustomTreeItemAdmin)
override_tree_admin(PortalTreeAdmin)

Django: 2.2 Django-sitetree: 1.16.0

idlesign commented 3 years ago

Thank you. I'll try to check this out in a week.

idlesign commented 3 years ago

I was unable to reproduce this by the given steps. Using your modification with demo project gave me the following:

sitetree

You may want to try to modify the demo accordingly, may be I've missed something.

iwalucas commented 3 years ago

@idlesign looks like yours is going under SiteTree module on admin.... mine is going to my Portal module.... I cant find a way of changing that

iwalucas commented 3 years ago

I will close it for now... I created a new app with lowercase, and it worked.... not sure whats the problem is

idlesign commented 3 years ago

I created a new app with lowercase, and it worked....

As a hint on module names in Python: https://www.python.org/dev/peps/pep-0008/#package-and-module-names