2009/12/22 Zeynel <azeyn...@gmail.com>:
> Thank you. Can you give me more detailed instructions about how to do
> this? I couldn't parse the referenced section of the documentation.
> How do I create the method "to generate anchor?" Where does the
> "method name" go in the admin.py?
>
> Thanks again.
>
> On Dec 14, 6:41 pm, rebus_ <r.dav...@gmail.com> wrote:
>> Create method on your model that generates anchor (html link tag)
>> which points to wanted URL and put that methods name in list_display
>> property of AdminModel object in your admin.py
>>
>> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri...
>

Hey,

Well, i was really short on my explanation there so let me elaborate.
I assume you have knowledge on what AdminModel is and what
list_display is used for.

Lets say you have model such as:

class SomeModel(models.Model):
    somefield = models.CharField(max_length=20)
    url = models.CharField(max_length=100)

    def some_url(self):
    """ This returns a HTML anchor (hyperlink) to somewhere  """
        return u'<a href="%s">Link</a>'  % self.url
    some_url.allow_tags = True

This model has some_url method defined which returns a plain HTML
link. When you create your AdminModel all you need to do is add the
name of them method to list_display attribute.

class SomeModelAdmin(admin.ModelAdmin):
    list_display = ('somefield', 'some_url')
site.register(SomeModel, SomeModelAdmin)

Using list_display attribute of AdminModel you can choose which fields
are to be display on change list in admin for that model.

So when the admin app parses the list_display attribute on AdminModel,
for each item in the sequence it tries to see if it is a field on
model, callable on Model or callable on AdminModel.

So what you need to do is create a method on your model that returns
the complete HTML link to lawyers bio and put that methods name in
list_display and your set to go.

Also notice the "some_url.allow_tags = True" under the method
definition. This tells Django's admin that it's ok not to encode HTML
tags. Without this the returned string would not be clickable but
rather shown as plain text.

Hope this helps.

Davor

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


Reply via email to