I've tried this.
The model is
class Advisors(models.Model):
advisorid = models.IntegerField(primary_key=True,
db_column='advisorId') # Field name made lowercase.
maphdid = models.ForeignKey(Tblmaphds, db_column='maPhDId') #
Field name made lowercase.
rank = models.SmallIntegerField()
def __unicode__(self):
return self.maphdid
class Meta:
db_table = u'Advisors'
in admin.py I have
def AdvisorAdmin(model):
class BrdgadvisorsAdmin(admin.ModelAdmin):
model = Brdgadvisors
list_display = [f.name for f in model._meta.fields]
return BrdgadvisorsAdmin
admin.site.register(Brdgadvisors,AdvisorAdmin(Brdgadvisors))
So this doesnt work.
On 26 Mart, 19:10, Karen Tracey <[email protected]> wrote:
> On Fri, Mar 26, 2010 at 4:31 PM, Asim Yuksel <[email protected]>wrote:
>
> > here is the list display
>
> >http://picasaweb.google.com/110428031719333287170/BaslKsZAlbum#545304...
>
> > I want that to appear in a list display, because that is what the
> > client wants :)
>
> > I tried writing unicode method , but it has no effect.I dont know
> > why.
>
> Since you haven't shown exactly what you tried there, we don't know either.
> As documented here:
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri...
>
> if the field is a ForeignKey, Django will display the __unicode__() of the
> related object.
>
> Thus if your Tblmaphds model had a __unicode__ method, whatever it returned
> would be what you see instead of "Tblmaphds object" in list display.
>
> Adding a __unicode__ method to that model is the easiest way to accomplish
> what you are asking for. There are also other options, as noted in that doc
> you can define callables on your model or model admin that return whatever
> you'd like to be shown in the list display, but really the easiest thing
> here would be the __unicode__ method on that model, so I'd suggest you try
> to figure out why that easiest solution isn't working before trying other
> more complicated things.
>
> Karen
--
You received this message because you are subscribed to the Google Groups
"Django users" 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-users?hl=en.