Hi saeb,

I believe you misunderstand the purpose of select_related().  When
used, it does the extra database work to retrieve related objects at
the beginning, rather than when you try to access them.  Here's an
example:

# in this example, notice how __dict__ isn't populated with the
_site_cache until AFTER we manually refer to the site (f.site.domain)

>>> from feedback.models import Feedback
>>> f = Feedback.objects.get(pk=1)
>>> f.__dict__
{'display_name': u'Keith', 'site_id': 1L, 'comments': u'YAY', 'id':
1L, 'pub_date': datetime.datetime(2008, 8, 1, 23, 35, 7)}
>>> f.site.domain
u'shopfha.com'
>>> f.__dict__
{'display_name': u'Keith', 'site_id': 1L, 'comments': u'hello', 'id':
1L, '_site_cache': <Site: example.com>, 'pub_date':
datetime.datetime(2008, 8, 1, 23, 35, 7)}


# in this example, notice how __dict__ is now populated with the
_site_cache without first referring to the site

>>> from feedback.models import Feedback
>>> f = Feedback.objects.select_related().get(pk=2)
>>> d.__dict__
{'display_name': u'Paul', 'site_id': 1L, 'comments': u"hello", 'id':
2L, '_site_cache': <Site: example.com>, 'pub_date':
datetime.datetime(2008, 8, 1, 23, 37, 41)}

HTH

Keith

On Aug 18, 11:50 pm, saeb <[EMAIL PROTECTED]> wrote:
> Sorry to ask a stupid question, but following is my basic model
> structure. I want to create a custom manager for a class which has a
> foreignKey to another class. And to call that manager function in list
> display to display all the related properties.  Am I doing it right? I
> don't see any associated fields when I execute the following in shell.
> Please help me with this issue, Thanks.
>
> class privateAcctManager(models.Manager):
>         def show_acct(self):
>                 return super(privateAcctManager,
> self).get_query_set().select_related()
>
> class privateAcct(models.Model):
>     id = models.ForeignKey(Acct)
>     obj = privateAcctManager()
>
>     def  all_acct(self):
>        return self.obj.show_acct()
>
>      class Meta:
>            db_table= 'private_acct'
>
> class PublicAcct(models.Model):
>     id = models.ForeignKey(Acct)
>      class Meta:
>            db_table= 'public_acct'
>
> class Account(models.Model):
>    name = models.TextField()
>    balance = models.decimalfield()
>
> class PrivateAcctAdmin(admin.modelAdmin):
> list_display =( id, all_acct.name , all_acct.balance)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to