Open bhargav066 opened 5 years ago
I think I'll need a bit more detail before I'm able to help you. A stripped down example of your models.py and admin.py, for instance
admin.py
from django.contrib import admin
from dashboard.models import Config, DataExtractors, NavigationExtractors
from django.contrib.auth.models import Group
import copy
import nested_admin
from nested_admin.forms import SortableHiddenMixin
class FormatInline(SortableHiddenMixin, nested_admin.NestedTabularInline):
extra = 0
sortable_field_name = 'position'
admin.site.site_header = 'dashboard'
admin.site.unregister(Group)
nav_depth_limit = 10
class DataExtractorsInLine(FormatInline):
model = DataExtractors
verbose_name = "Data Extractor"
verbose_name_plural = "Data Extractors"
exclude = ('navigation_fk',)
class NavDataExtractorsInLine(FormatInline):
model = DataExtractors
verbose_name = "NAV Data Extractor"
verbose_name_plural = "NAV Data Extractors"
exclude = ('navigation_fk', 'data_config_fk')
nav_attr_dict = {
'model': NavigationExtractors,
'inlines': [NavDataExtractorsInLine],
'exclude': ('child_navigator_fk', 'nav_config_fk'),
}
temp_var = [copy.deepcopy(nav_attr_dict) for _ in range(nav_depth_limit)]
for i in range(nav_depth_limit-1):
temp_var[i]['inlines'].append(type('NavigationExtractorInLine', (FormatInline,), temp_var[i+1]))
nav_dict = temp_var[0]
del temp_var
class NavigationExtractorInLine(FormatInline):
model = NavigationExtractors
inlines = [NavDataExtractorsInLine, type('NavigationExtractorInLine', (FormatInline,), nav_dict)]
exclude = ('child_navigator_fk',)
class ConfigAdmin(nested_admin.NestedModelAdmin):
inlines = [DataExtractorsInLine, NavigationExtractorInLine]
admin.site.register(Config, ConfigAdmin)
models.py
from django.db import models
class Config(models.Model):
config_id = models.PositiveIntegerField(primary_key=True)
config_name = models.CharField(max_length=200, null=False)
schema = models.CharField(max_length=100, null=True)
class Meta:
db_table = 'crawler_configs'
class NavigationExtractors(models.Model):
ext_name = models.CharField(max_length=200, null=False)
position = models.PositiveIntegerField(default=0, null=True)
child_navigator_fk = models.ForeignKey('self', null=True, on_delete=models.CASCADE, related_name='parent_navigator_fk')
nav_config_fk = models.ForeignKey(Config, null=True, on_delete=models.CASCADE, related_name='nav_config_fk')
class Meta:
db_table = 'navigation_extractors'
ordering = ['position']
class DataExtractors(models.Model):
name = models.CharField(max_length=200, null=False)
position = models.PositiveIntegerField(default=0, null=True)
data_config_fk = models.ForeignKey(Config, blank=True, null=True, on_delete=models.CASCADE, related_name='data_config_fk')
navigation_fk = models.ForeignKey(NavigationExtractors,blank=True, null=True, on_delete=models.CASCADE, related_name='navigation_fk')
class Meta:
db_table = 'data_extractors'
ordering = ['position']
here I am trying to make a model inline to itself until to a depth of 30 for that I generated classes using type inbuilt function, the problem I am getting is for config inlines (admin model ) I am able to sort the data-inline and navigation-inline, but for inlines under navigation drag-and-sort is not working , even if I remove recursive inline for navigation inline and keep only data inline still that problem exists
i am using nestedtabularinline in my project drag-and-drop is not working after first level inlines