Proxy models, with an associated Manager, are one way to achieve this - assuming your criteria are fixed.
On Monday, 15 April 2019 15:25:49 UTC+2, Balaji Shetty wrote: > > Hi > > When i do login using Django Admin Panel , i can easily perform CRUD > operation on Models. > > can i customize the display of Models Records in django Admin Panel > Itself, when I select the model, I get all the records, But i want to > filter the records based on some Criteria. > > Here is my model . Code executes. > > > > class EmployeeManager(models.Manager): > def get_queryset(self): > return super(EmployeeManager, > self).get_queryset().filter(gender='F') > > > > > > class Employee(models.Model): > gender_choices = ( > ("M", "Male"), > ("F", "Female") > ) > roles_choices = ( > ("J", "Junior"), > ("S", "Senior"), > ) > first_name = models.CharField(max_length=200) > last_name = models.CharField(max_length=200) > email = models.CharField(max_length=250) > gender = models.CharField(max_length=1, choices=gender_choices) > role = models.CharField(max_length=120, choices=roles_choices, > default="J") > active = models.BooleanField(default=True) > > # custom manager replaces objects manger > all_employees = models.Manager() > objects = models.Manager() # The default manager. > active_objects = EmployeeManager() # The EmployeeManager manager. > > def __str__(self): > return str(self.first_name) + str(self.last_name) > > From Shell, it executes. > > # Employee.active_objects.all() > # Employee.active_objects.filter(email='empl...@gmail.com > <javascript:>') > # Employee.active_objects.count() > > Source: > https://micropyramid.com/blog/how-to-add-a-custom-managers-in-django/ > > When > > My Query is can i show the filtered record in directly Django Admin Panel > after doing Login based on Logged User Username. > > > -- > > > *Mr. Shetty Balaji S.Asst. ProfessorDepartment of Information Technology,* > *SGGS Institute of Engineering & Technology, Vishnupuri, Nanded.MH.India* > *Official: bssh...@sggs.ac.in <javascript:> * > * Mobile: +91-9270696267* > > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/91b6e1ab-735f-4824-85ad-f82640af67ea%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.