나는 GenericTabularInline 클래스를 상속하고 BaseModelAdmin 클래스의 일부 메소드를 오버라이드하여 두 관리자 용 2 데이터베이스 설정에서 작동하도록 만들었으며 Django 문서 (https : //docs.djangoproject.com/en/dev/topics/db/multi-db/), 자식 모델이 인라인 형식으로 편집되면 기본 데이터베이스에 항상 씁니다 (두 번째 관리자가 처리해야 함). 보조 데이터베이스와 독점적으로, 모델은 두 모델 모두 동일합니다.) 그래서 어떤 메소드를 오버라이드하거나 잘못된 작업을해서는 안됩니다. 지금까지 내가 가지고있는 수업은 다음과 같습니다.Django GenericTabularInline 다중 데이터베이스
class MultiDBGenericTabularInline(generic.GenericTabularInline):
using = settings.SECONDARY_DATABASE
def save_model(self, request, obj, form, change):
# Tell Django to save objects to the 'other' database.
obj.save(using=self.using)
def delete_model(self, request, obj):
# Tell Django to delete objects from the 'other' database
obj.delete(using=self.using)
def queryset(self, request):
# Tell Django to look for objects on the 'other' database.
return super(MultiDBGenericTabularInline, self).queryset(request).using(self.using)
def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
# Tell Django to populate ForeignKey widgets using a query
# on the 'other' database.
return super(MultiDBGenericTabularInline, self).formfield_for_foreignkey(db_field, request=request, using=self.using, **kwargs)
def formfield_for_manytomany(self, db_field, request=None, **kwargs):
# Tell Django to populate ManyToMany widgets using a query
# on the 'other' database.
return super(MultiDBGenericTabularInline, self).formfield_for_manytomany(db_field, request=request, using=self.using, **kwargs)
#Override these three methods; otherwise the log manager attempts
#to write to the main db and raises an exception.
def log_addition(self, request, object):
pass
def log_change(self, request, object, message):
pass
def log_deletion(self, request, object, object_repr):
pass
어떤 도움이나 힌트를 부탁드립니다.