Skip to content

Commit

Permalink
registered models on django
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullai-t committed Dec 5, 2023
1 parent f9faf41 commit 54e8ce4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
3 changes: 0 additions & 3 deletions src/api/store/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ def list_campaigns_for_admins(self, context: Context, args) -> Tuple[list, MassE

if context.user_is_super_admin:
return self.list_campaigns_for_super_admin(context)




if subdomain:
campaigns = Campaign.objects.filter(account__subdomain = subdomain).select_related('logo').filter(is_deleted=False)
Expand Down
47 changes: 46 additions & 1 deletion src/apps__campaigns/admin.py
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()

0 comments on commit 54e8ce4

Please sign in to comment.