-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9faf41
commit 54e8ce4
Showing
2 changed files
with
46 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,48 @@ | ||
from django.contrib import admin | ||
import apps__campaigns.models as module | ||
import django.db.models.base as Base | ||
from _main_.utils.constants import GLOBAL_SITE_SETTINGS | ||
from _main_.utils.utils import get_all_models | ||
from database.views import clean_all_selected_subdomains | ||
|
||
# Register your models here. | ||
# changing the default django site name | ||
admin.site.site_header = GLOBAL_SITE_SETTINGS["ADMIN_SITE_HEADER"] | ||
|
||
|
||
|
||
sample = ["title", "name", "email", "full_name", "id", "updated_at", "template_id"] | ||
sample_filter = ["created_at", "is_published", "is_deleted", "is_approved", "is_global"] | ||
|
||
|
||
def register_all_models(): | ||
""" | ||
This function handles the registration of all the models inside of | ||
database.models. | ||
It returns True if succeeded and False otherwise | ||
""" | ||
all_database_models = get_all_models(module) | ||
|
||
success = True | ||
for model in all_database_models: | ||
try: | ||
if ( | ||
not model._meta.abstract | ||
): # can't register abstract models (namely PageSettings) | ||
fields = [field.name for field in model._meta.get_fields()] | ||
viable_search = [i for i in fields if i in sample] | ||
viable_filter = [i for i in fields if i in sample_filter] | ||
|
||
class AdminSetup(admin.ModelAdmin): | ||
list_display = viable_search | ||
search_fields = viable_search | ||
list_filter = viable_filter | ||
|
||
admin.site.register(model, AdminSetup) | ||
except admin.sites.AlreadyRegistered: | ||
success = False | ||
return success | ||
|
||
|
||
# Register all models | ||
register_all_models() |