По какой-то причине, после сохранения модели Project
в django-admin дочерние элементы не отображаются в форме, хотя само сохранение происходит.
Пробовал упразднить и get_fields
и get_inline_instances
, но это ни к чему не привело.
При этом, Activity
, отображается, а остальные - нет.
class InlineActivityAdmin(GenericStackedInline):
model = Activity
form = ActivityForm
extra = 1
class InlinePriceAdmin(CompactInline):
model = Price
extra = 1
class InlineInvoiceAdmin(CompactInline):
model = Invoice
readonly_fields = ['state']
@admin.register(Project)
class ProjectAdmin(FSMTransitionMixin, BaseAdmin):
inlines = [
InlineActivityAdmin,
InlineInvoiceAdmin,
InlinePriceAdmin,
]
list_display = ['pk', 'state','address', 'assignment_phone_number', 'assignment_client_name']
list_filter = ('state', )
readonly_fields = ('state', 'assignment_phone_number', 'assignment_client_name')
def get_fields(self, request, obj):
if obj:
if not request.user.is_superuser:
if obj.state == 'complete_work':
return ['state', 'address', 'assignment_phone_number', 'assignment_client_name',
'project_service', 'project_trouble']
elif obj.state == 'started_diagnostic':
return ['state', 'address', 'assignment_phone_number', 'assignment_client_name',
'diagnostic_service', 'diagnostic_trouble']
else:
return ['state', 'address', 'assignment_phone_number', 'assignment_client_name']
return super(ProjectAdmin, self).get_fields(request, obj)
def get_inline_instances(self, request, obj):
inlines = []
if obj:
if not request.user.is_superuser:
if obj.state == 'take_invoce':
for inline_class in self.inlines:
if inline_class is not InlineInvoiceAdmin:
inline = inline_class(self.model, self.admin_site)
inlines.append(inline)
return inlines
return super(ProjectAdmin, self).get_inline_instances(request, obj)