Hi,

Trying to make a custom model admin form for a staff user (not a
superuser), I had to override ModelAdmin.get_readonly_fields() and
ModelAdmin.get_fieldsets(). The problem arrives when i try to change
the data of a model record, because the field is mandatory
(blank=False, as default). When i submit the form, i got an error on
top of the form, without any specification. In spanish "Por favor,
corrija los siguientes errores.", i think in english "Please, fix the
errors".

For example,

in models.py

Class Foo(model.Models):
  name = models.CharField(max_length=100)
  other = models.CharField(max_length=100)
...
...

in admin.py


class FooAdmin(admin.ModelAdmin):
    fieldsets = [
        ('Data 1', {'fields': ['name',...]}),
        ('Data 2', {'fields': ['other',..]}),
        ]
    fieldsets_custom= [
        ('Data 1', {'fields': ['name',..]}),
        ('Data 2', {'fields': ['other',...]}),
       ]
    readonly_fields_custom = ('name',)

    def get_readonly_fields(self, request, obj=None):
       if (request.user.is_superuser):
          return self.readonly_fields
       else:
          return self.readonly_fields_custom

    def get_fieldsets(self, request, obj=None):
       if (request.user.is_superuser):
          return super(FooAdmin, self).get_fieldsets(request,
obj=None)
       else :
          return self.fieldsets_custom


Any idea?
Can i override clean() to avoid validation over name field?
Other idea to got a custom admin form with readonly mandatory fields
(an exclude some others)?

Thanx, Mario.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to