Tuesday, May 28, 2013

Admin for proxy model for custom User

Hi everyone, I've created a custom User model and reated a proxy for
it, like this:

class User(AbstractUser):
USER_KINDS = (
('d', 'doctor'),
('p', 'patient')
)
kind = models.CharField(max_length=2, choices=USER_KINDS)

class DoctorManager(BaseUserManager):
def get_queryset(self):
return super(DoctorManager, self).get_queryset().filter(kind='d')


class PatientManager(BaseUserManager):
def get_queryset(self):
return super(DoctorManager, self).get_queryset().filter(kind='p')


class Doctor(User):
objects = DoctorManager()

class Meta:
proxy = True


class Patient(User):
objects = PatientManager()

class Meta:
proxy = True

----------------------------------------


Now, my admin has the following code:

# Forms subclassing default auth forms
class DemographicsUserAdmin(reversion.VersionAdmin, UserAdmin):
form = DemographicsUserChangeForm
add_form = DemographicsUserCreationForm

class PatientAdmin(admin.ModelAdmin):
add_form_template = 'admin/auth/user/add_form.html'
form = PatientChangeForm
add_form = PatientCreationForm

def get_queryset(self, request):
return Patient.objects.all()

class DoctorAdmin(admin.ModelAdmin):
add_form_template = 'admin/auth/user/add_form.html'
form = PatientChangeForm
add_form = PatientCreationForm

def get_queryset(self, request):
return Doctor.objects.all()



admin.site.register(User, DemographicsUserAdmin)
admin.site.register(Doctor, DoctorAdmin)
admin.site.register(Patient, PatientAdmin)

------------------------------------------------------


Now, this would seem to indicate that the proxy model admins would be
filtering only those users with the proper kind. However, not only is
this not happening, but the get_queryset() methods for either admins
is not running, nor the default objects() manager. Any idea why this
would be happening?

Andrés Osinski
http://www.andresosinski.com.ar/

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

No comments:

Post a Comment