Monday, March 2, 2015

Re: Using proxy kind of Table in Admin Interface

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)


On Monday, March 2, 2015 at 12:21:47 PM UTC-5, Derek wrote:
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)


On Monday, 2 March 2015 18:16:36 UTC+2, Rootz wrote:
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 

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/19bc578f-1704-4a58-a068-13b89139c859%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment