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


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):
    for x in LocationCode._meta.get_all_field_names():

admin.site.register(LocationCode, LocationAdmin)

in url.py add these line

from django.contrib import admin


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


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: 

Leave a comment