Ticket #12481: django-admin-readonly-editable.diff

File django-admin-readonly-editable.diff, 2.1 KB (added by Alex Gaynor, 15 years ago)

Tests + fix.

  • django/contrib/admin/validation.py

    diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py
    index 94d4bbd..f743f2c 100644
    a b def validate_base(cls, model):  
    245245                if type(fields) != tuple:
    246246                    fields = (fields,)
    247247                for field in fields:
     248                    if field in cls.readonly_fields:
     249                        # Stuff can be put in fields that isn't actually a
     250                        # model field if it's in readonly_fields,
     251                        # readonly_fields will handle the validation of such
     252                        # things.
     253                        continue
    248254                    check_formfield(cls, model, opts, "fieldsets[%d][1]['fields']" % idx, field)
    249255                    try:
    250256                        f = opts.get_field(field)
  • tests/regressiontests/admin_validation/models.py

    diff --git a/tests/regressiontests/admin_validation/models.py b/tests/regressiontests/admin_validation/models.py
    index ef65c45..b507648 100644
    a b class Album(models.Model):  
    1212class Song(models.Model):
    1313    title = models.CharField(max_length=150)
    1414    album = models.ForeignKey(Album)
     15    original_release = models.DateField(editable=False)
    1516
    1617    class Meta:
    1718        ordering = ('title',)
  • new file tests/regressiontests/admin_validation/tests.py

    diff --git a/tests/regressiontests/admin_validation/tests.py b/tests/regressiontests/admin_validation/tests.py
    new file mode 100644
    index 0000000..9166360
    - +  
     1from django.contrib import admin
     2from django.contrib.admin.validation import validate
     3from django.test import TestCase
     4
     5from models import Song
     6
     7
     8class ValidationTestCase(TestCase):
     9    def test_readonly_and_editable(self):
     10        class SongAdmin(admin.ModelAdmin):
     11            readonly_fields = ["original_release"]
     12            fieldsets = [
     13                (None, {
     14                    "fields": ["title", "original_release"],
     15                }),
     16            ]
     17       
     18        validate(SongAdmin, Song)
Back to Top