﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14496	Conflict between ModelForm.Meta.exclude and ModelAdmin.readonly attributes	msgre_valise	nobody	"I have problem with contrib.admin application. Consider we have demo application with this three files:

demo/models.py:
{{{
    from django.db import models

    class Demo(models.Model):
        name = models.CharField(max_length=100)
        note = models.TextField(blank=True, null=True)
}}}


demo/admin.py:
{{{
    from django.contrib import admin
    from models import Demo
    from forms import DemoAdminForm

    class DemoAdmin(admin.ModelAdmin):
        readonly_fields = ('name', )
        form = DemoAdminForm

    admin.site.register(Demo, DemoAdmin)
}}}

demo/forms.py:
{{{
    from django import forms
    from models import Demo

    class DemoAdminForm(forms.ModelForm):
        class Meta:
            model = Demo
            exclude = ('note', )
}}}

If I go to administration, and edit some Demo object, I see two fields: editable Note and readonly Name. But! I should see only readonly Name (because I use own ModelForm class which excluded note field). Try to comment line ""readonly_fields = ('name', )"" at admin.py file. You will see, that in this situation (no readonly attribute on ModelAdmin) Django correctly accept Meta class on ModelForm and exclude field Note.

I think that there is a problem in the way, how Django construct ModelForm class. It don't respect Meta classes in Form, if there is at same time readonly attribute on ModelAdmin."	Bug	closed	contrib.admin	1.2	Normal	fixed	ModelForm ModelAdmin readonly_fields exclude conflict		Ready for checkin	1	0	0	0	0	0
