Malcolm,
So how do I call a method in my list_display?  Here is my models file

class Manufacturer(models.Model):
        name = models.CharField(maxlength=200)
        manufacturerslug = models.SlugField(prepopulate_from=["name"])
        description = models.TextField(maxlength=1000)

        def __str__(self,):
                return self.name

        class Admin:
                pass

class Collection(models.Model):
        name = models.CharField(maxlength=200)
        collectionslug = models.SlugField(prepopulate_from=["name"])
        description = models.TextField(maxlength=1000)
        manufacturer = models.ForeignKey(Manufacturer)

        def __str__(self,):
                return self.name

        class Admin:
                pass

class Style(models.Model):
    name = models.CharField(maxlength=200)
    theslug = models.SlugField(prepopulate_from=('name',))
    collection = models.ForeignKey(Collection)


    class Admin:
        search_fields = ['name']
        list_display = ('name', 'theslug','collection', rmanu())

    def __str__(self,):
        return self.name

    def rmanu(self,):
        return self.collection.manufacturer




Here is what I get when I try to call the method in a python shell

>>> from mysite.rugs.models import Style
>>> s = Style.objects.filter(id=1)
>>> s
[<Style: 89b>]
>>> s.rmanu()
Traceback (most recent call last):
  File "<console>", line 1, in ?
AttributeError: 'QuerySet' object has no attribute 'rmanu'
>>>

I thought that was how I call a method?

Thanks




On May 23, 5:14 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Wed, 2007-05-23 at 14:33 -0700, Greg wrote:
> > I'm having a problem displaying data in my admin using list_display.
> > I want to be able to show the Manufacturer in the admin from my styles
> > page.  Here are my models:
>
> > class Manufacturer(models.Model):
> >    name = models.CharField(maxlength=200)
> >    manufacturerslug = models.SlugField(prepopulate_from=["name"])
> >    description = models.TextField(maxlength=1000)
>
> >         def __str__(self,):
> >            return self.name
>
> >    class Admin:
> >            pass
>
> > class Collection(models.Model):
> >    name = models.CharField(maxlength=200)
> >    collectionslug = models.SlugField(prepopulate_from=["name"])
> >    description = models.TextField(maxlength=1000)
> >    manufacturer = models.ForeignKey(Manufacturer)
>
> >    def __str__(self,):
> >            return self.name
>
> >    class Admin:
> >            pass
>
> > class Style(models.Model):
> >     name = models.CharField(maxlength=200)
> >     theslug = models.SlugField(prepopulate_from=('name',))
> >     collection = models.ForeignKey(Collection)
>
> >     class Admin:
> >    search_fields = ['name']
> >    list_display = ('name', 'theslug','collection',
> > 'collection.manufacturer')
>
> >     def __str__(self,):
> >    return self.name
>
> > When I view my style table in the admin I want to be able to display
> > the manufacturer.  However, I don't have a manufacturer field in the
> > Style table.  All I have is a foreign key to collection, which
> > contains a foreignkey to manufacturer.  I have no problem displaying
> > the collection that the style is associated with.  I want to be able
> > to show the manufacturer of the style in the admin.
>
> > I currently do "list_display = ('name', 'theslug', 'collection',
> > 'collection.manufacturer')" However it errors when
> > 'collection.manufacurer'.  Is it possible for me to show the
> > Manufacturer of the style in the admin?
>
> Doing list_display lookups across models like this doesn't work, as
> you've discovered. One day we might even fix that, because it's about a
> four line change to fix.
>
> For the time being, the simplest solution is to create a method that
> returns collection.manufacturer and use that method name in the
> list_display list. You can even make this field sortable using the
> admin_order_field attribute on the function (search the model-api docs
> for more information), I suspect.
>
> Regards,
> Malcolm- Hide quoted text -
>
> - Show quoted text -


--~--~---------~--~----~------------~-------~--~----~
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