Django proxy model and admin
So I'm starting a new Django app and I'm creating a UserProfile model which is a proxy for django.contrib.auth.models.User, as follows:


    from django.db import models
    from django.contrib.auth.models import User
    
    class UserProfile(models.Model):
        user = models.OneToOneField(User, related_name='profile')
        
        # make this a proxy model for user
        def __getattr__(self, name, *args):
            if name == 'user' or name == '_user_cache':
                raise AttributeError(name)
            
            try:
                return getattr(self.user, name, *args)
            except AttributeError, e:
                raise AttributeError(name)


This works fine in general, but breaks when I try to use a proxied field in ModelAdmin.list_display.  The problem is in the admin validation code here:

    def validate(cls, model):
        """
        Does basic ModelAdmin option validation. Calls custom validation
        classmethod in the end if it is provided in cls. The signature of the
        custom validation classmethod should be: def validate(cls, model).
        """
        # Before we can introspect models, they need to be fully loaded so that
        # inter-relations are set up correctly. We force that here.
        models.get_apps()
    
        opts = model._meta
        validate_base(cls, model)
    
        # list_display
        if hasattr(cls, 'list_display'):
            check_isseq(cls, 'list_display', cls.list_display)
            for idx, field in enumerate(cls.list_display):
                if not callable(field):
                    if not hasattr(cls, field):
                        if not hasattr(model, field):
                            try:
                                opts.get_field(field)
                            except models.FieldDoesNotExist:
                                raise ImproperlyConfigured("%s.list_display[%d], %r is not a callable or an attribute of %r or found in the model %r."
                                    % (cls.__name__, idx, field, cls.__name__, model._meta.object_name))


The problem is that while an instance of UserProfile will have proxied fields, e.g. email, the UserProfile class itself doesn't.  Demoed in the Django shell:


    >>> hasattr(UserProfile, 'email')
    False
    >>> hasattr(UserProfile.objects.all()[0], 'email')
    True


But `hasattr(User, 'email')` also returns false - so why, in the Auth.Users admin section, does `'email'` being in its `list_display` work?

My last attempt was as follows:  I subclassed django.db.models.base.ModelBase and overrode `__getattr__` there, and then set `UserProfile.__metaclass__` to that subclass.  This didn't help.

So my two (related) questions are:

* How can `'email'` being in `list_display` for the auth.User ModelAdmin pass the validation code above?
* More importantly, how can I get my UserProfile proxy fields to pass this same validation?

Thanks.
Django proxy model and admin
===

So I'm starting a new Django app and I'm creating a UserProfile model which is a proxy for django.contrib.auth.models.User, as follows:


    from django.db import models
    from django.contrib.auth.models import User
    
    class UserProfile(models.Model):
        user = models.OneToOneField(User, related_name='profile')
        
        # make this a proxy model for user
        def __getattr__(self, name, *args):
            if name == 'user' or name == '_user_cache':
                raise AttributeError(name)
            
            try:
                return getattr(self.user, name, *args)
            except AttributeError, e:
                raise AttributeError(name)


This works fine in general, but breaks when I try to use a proxied field in ModelAdmin.list_display.  The problem is in the admin validation code here:

    def validate(cls, model):
        """
        Does basic ModelAdmin option validation. Calls custom validation
        classmethod in the end if it is provided in cls. The signature of the
        custom validation classmethod should be: def validate(cls, model).
        """
        # Before we can introspect models, they need to be fully loaded so that
        # inter-relations are set up correctly. We force that here.
        models.get_apps()
    
        opts = model._meta
        validate_base(cls, model)
    
        # list_display
        if hasattr(cls, 'list_display'):
            check_isseq(cls, 'list_display', cls.list_display)
            for idx, field in enumerate(cls.list_display):
                if not callable(field):
                    if not hasattr(cls, field):
                        if not hasattr(model, field):
                            try:
                                opts.get_field(field)
                            except models.FieldDoesNotExist:
                                raise ImproperlyConfigured("%s.list_display[%d], %r is not a callable or an attribute of %r or found in the model %r."
                                    % (cls.__name__, idx, field, cls.__name__, model._meta.object_name))


The problem is that while an instance of UserProfile will have proxied fields, e.g. email, the UserProfile class itself doesn't.  Demoed in the Django shell:


    >>> hasattr(UserProfile, 'email')
    False
    >>> hasattr(UserProfile.objects.all()[0], 'email')
    True


But `hasattr(User, 'email')` also returns false - so why, in the Auth.Users admin section, does `'email'` being in its `list_display` work?

My last attempt was as follows:  I subclassed django.db.models.base.ModelBase and overrode `__getattr__` there, and then set `UserProfile.__metaclass__` to that subclass.  This didn't help.

So my two (related) questions are:

* How can `'email'` being in `list_display` for the auth.User ModelAdmin pass the validation code above?
* More importantly, how can I get my UserProfile proxy fields to pass this same validation?

Thanks.