[Fixed]-Is there any official way to get the admin options of a model?

3👍

first create model

from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.db import models
class LocationCode(models.Model):
    """
    A web service that will allow user to create there price rule based on conditions
    """
    name = models.CharField(max_length=255)
    code = models.CharField(max_length=255)

    def __unicode__(self):
        return self.name

in admin.py you need to add code

from django.contrib import admin
from dx_man.models import LocationCode 
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

class LocationAdmin(admin.ModelAdmin):
    list_display=[]
    for x in LocationCode._meta.get_all_field_names():
        list_display.append(str(x))

admin.site.register(LocationCode, LocationAdmin)

in url.py add these line

from django.contrib import admin
admin.autodiscover()

1👍

You need to ensure the registration code has been run or the site will not contain the (model, modeladmin) in the _registry.

code.py

from django.contrib.admin.sites import site

# run admin registration code before we get here
for model, model_admin in site._registry.items():
    if model == whatevermodel: 
        print(model_admin.search_fields)

Leave a comment