#3416: Model API documentation section 'Modifying initial Manager QuerySets'
misleads about Admin behaviour
--------------------------+-------------------------------------------------
   Reporter:  Alex Dedul  |                Owner:  jacob        
     Status:  new         |            Component:  Documentation
    Version:  SVN         |           Resolution:               
   Keywords:              |                Stage:  Unreviewed   
  Has_patch:  0           |           Needs_docs:  0            
Needs_tests:  0           |   Needs_better_patch:  0            
--------------------------+-------------------------------------------------
Comment (by Alex Dedul):

 Here we go. Test case 1:
 
 {{{
 class KnowledgeBaseCategoryManager(models.Manager):
     def get_query_set(self):
         return super(KnowledgeBaseCategoryManager, self).get_query_set().\
                    filter(name='test')
 
 class KnowledgeBaseCategory(models.Model):
     name = models.CharField(maxlength=100, unique=True)
 
     class Meta:
         verbose_name_plural = 'Knowledge Base Categories'
         ordering = ('name', )
 
     class Admin:
         search_fields = ('name',)
         manager = KnowledgeBaseCategoryManager()
 
     def __str__(self):
         return self.name
 
 >>> KnowledgeBaseCategory.objects.all()
 [<KnowledgeBaseCategory: test>, <KnowledgeBaseCategory: test2>]
 }}}
 
 KnowledgeBaseCategory has 2 records with name 'test' and 'test2', but in
 admin's change list there is only one record with name 'test' because of
 manager attribute of inner Admin class.
 
 Test case 2:
 
 {{{
 # KnowledgeBaseCategoryManager is the same
 
 class KnowledgeBaseCategory(models.Model):
     name = models.CharField(maxlength=100, unique=True)
 
     test_manager = KnowledgeBaseCategoryManager()
 
     class Meta:
         verbose_name_plural = 'Knowledge Base Categories'
         ordering = ('name', )
 
     class Admin:
         search_fields = ('name',)
 
     def __str__(self):
         return self.name
 
 >>> KnowledgeBaseCategory.test_manager.all()
 [<KnowledgeBaseCategory: test>]
 }}}
 
 Here is custom test_manager returns only 1 record 'test' as expected, but
 in admin's change list both 'test' and 'test2' records are displayed.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/3416#comment:4>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to