djangodjango-urlsdjango-url-reverse

When I try to add some data in database from admin, Iam getting NoReverseMatch error


Here I am not using any admin template. I am using the default admin template. How can I reverse this url?

The error which I get:

NoReverseMatch at /admin/machine/module/add/
Reverse for 'machine_module_change' with arguments '('',)' not found. 1 pattern(s) tried: ['admin/machine/module/(?P<object_id>.+)/change/$']
Request Method: POST
Request URL:    http://localhost:8080/admin/machine/module/add/
Django Version: 3.0.8
Exception Type: NoReverseMatch
Exception Value:    
Reverse for 'machine_module_change' with arguments '('',)' not found. 1 pattern(s) tried: ['admin/machine/module/(?P<object_id>.+)/change/$']
Python Version: 3.7.7
Python Path:    
['C:\\Users\\Administrator\\Documents\\CheckMeOut\\checkmeout',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\DLLs',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\lib',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37',
 'C:\\Users\\Administrator\\AppData\\Roaming\\Python\\Python37\\site-packages',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages',
 'C:/Users/Administrator/Documents/CheckMeOut/checkmeout',
 'C:/Users/Administrator/Documents/CheckMeOut/checkmeout/checkmeout']
Server time:    Tue, 2 Mar 2021 15:21:42 +0530

urls.py

from django.contrib import admin    
from django.urls import path, include    
from django.conf import settings    
from django.conf.urls.static import static    
from django.urls import reverse

urlpatterns = [    
    path('', include('main.urls')),    
    path('equipment/', include('equipment.urls')),    
    path('machine/', include('machine.urls')),    
    path('admin/',admin.site.urls),    
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)

Solution

  • I did it in admin.py and I solved the issue.

    Changed code:

    @admin.register(Module)
    class ModuleAdmin(admin.ModelAdmin):
        # fieldsets = (
        #     ('Information', {
        #         'fields': ('name', 'model', 'serialNumber', 'slot')
        #     }),
        # )
        search_fields = ['name', 'model', 'serialNumber']
        list_display = ('name', 'model', 'serialNumber', 'slot')
        list_per_page = 15
    

    Here I just commented on those fieldsets.. So it fixed the issue. Please explain to me how it happened?