Сохраниться

This commit is contained in:
iriska-gri committed 2023-11-21 16:59:20 +03:00
1 parent 88bd3fcdaa
commit 1c0764d1ea
10 files changed
+30 -51

No files matched your search

+3 -28
View File
@@ -2,41 +2,16 @@ from django.contrib import admin
from .models import *
from django.db.models import Q
# Register your models here.
class MultiDBModelAdmin(admin.ModelAdmin):
class DictEmployeeAdmin(admin.ModelAdmin):
# A handy constant for the name of the alternate database.
using = "user_directory"
# using = "user_directory"
list_display=('fio', 'login', 'birthdate')
search_fields = ('login', 'fio',)
list_editable=('birthdate',)
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 get_queryset(self, request):
# Tell Django to look for objects on the 'other' database.
return super().get_queryset(request).using(self.using).filter(~Q(deleted=1))
def formfield_for_foreignkey(self, db_field, request, **kwargs):
# Tell Django to populate ForeignKey widgets using a query
# on the 'other' database.
return super().formfield_for_foreignkey(
db_field, request, using=self.using, **kwargs
)
def formfield_for_manytomany(self, db_field, request, **kwargs):
# Tell Django to populate ManyToMany widgets using a query
# on the 'other' database.
return super().formfield_for_manytomany(
db_field, request, using=self.using, **kwargs
)
# class DictEmployeeAdmin(admin.ModelAdmin):
admin.site.register(DictEmployee, MultiDBModelAdmin)
admin.site.register(DictEmployee,DictEmployeeAdmin)