Using proxy kind of Table in Admin Interface

87 views
Skip to first unread message

Rootz

unread,
Mar 2, 2015, 11:16:36 AM3/2/15
to django...@googlegroups.com
Question.
How would one go about designing the django table(s) so that I can assign each user account/group a different Model Manager using the same table in the Django admin interface? 

After doing some reading the closest that comes to this is the Proxy Model but I tried adding the proxy model manually into the django admin and I got it to work. However when I try to assign permission to each user account for the different proxy models I had created I am only  see only one proxy model in the permission list (django admin interface).

My goal is to create one table that returns a custom QuerySet unique to a user group or user account. Adding to this I would like for this to be visible in the admin interface. Can you guide me as to how can achieve this.

thank you 

Derek

unread,
Mar 2, 2015, 12:21:47 PM3/2/15
to django...@googlegroups.com
I am not quite sure what you are trying to achieve (without seeing sample code), but here is some very basic code showing how a proxy could work:

models.py

class MainModel(Model):
   """mother of models"""
    ...
    

class MainModelProxy(MainModel):
    objects = MainModelProxyManager()

    class Meta:
        proxy = True


admin.py

class MainModelAdmin(ModelAdmin):
    """mother of all admin"""
    ...


class MainModelProxyAdmin(MainModelAdmin):
    #add salt to taste
    

admin.site.register(MainModel, MainModelAdmin)
admin.site.register(MainModelProxy, MainModelProxyAdmin)

Rootz

unread,
Mar 2, 2015, 1:40:55 PM3/2/15
to django...@googlegroups.com
Ok below is a sample of the models.py


class LocationProfile(models.Model):
    shortName
= models.CharField('Location Name',max_length=100,primary_key = True)
    longName
= models.CharField('Church Name',max_length=100)
   
.........

class Member(models.Model):
    first
= models.CharField('First Name',max_length=150)
   
last =  models.CharField('Last Name',max_length=150)
   
.........

###Meadowvale SDA
###Model Manager
class MeadowvaleManager(models.Manager):
   
def get_queryset(self):
       
return super(MeadowvaleManager, self).get_queryset().filter(churchLoc='meadow-sda')


###Model Proxy
class MeadowvaleMember(Member):
    objects
= MeadowvaleManager()
   
   
class Meta:
        verbose_name
= "MeadowMember"
        proxy
= True
   


####Another SDA
###Model Manager
class AnotherManager(models.Manager):
   
def get_queryset(self):
       
return super(AnotherManager, self).get_queryset().filter(id=1)


###Model Proxy
class AnotherMember(Member):
    objects
= AnotherManager()
   
   
class Meta:
        verbose_name
= "AnotherMember"
        proxy
= True



below is a sample of the admin.py

from members.mymodels.models import MeadowvaleMember,AnotherMember
 
class MeadowvaleMemberAdmin(admin.ModelAdmin):
   
def get_query_set(self,request):
       
return MeadowvaleMember.objects.all()
   
   
class AnotherMemberAdmin(admin.ModelAdmin):
   
def get_query_set(self,request):
       
return AnotherMember.objects.all()

#proxy

admin
.site.register(MeadowvaleMember,MeadowvaleMemberAdmin)
admin
.site.register(AnotherMember,AnotherMemberAdmin)

Simon Charette

unread,
Mar 3, 2015, 12:26:05 AM3/3/15
to django...@googlegroups.com
Hi Rootz,

Unfortunately there's a long standing ticket to solve inconsistency with permissions for proxy models  so your chosen approach won't work until this is fixed.

Simon

Rootz

unread,
Mar 3, 2015, 10:49:46 AM3/3/15
to django...@googlegroups.com
Thanks 
Reply all
Reply to author
Forward
0 new messages