Re: Clickable url in the admin

2009-12-22 Thread rebus_
2009/12/22 Zeynel :
> 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_  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'Link'  % 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.




Re: Clickable url in the admin

2009-12-22 Thread Zeynel
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_  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...

--

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.




Re: Clickable url in the admin

2009-12-14 Thread rebus_
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.contrib.admin.ModelAdmin.list_display

--

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.




Re: Clickable url in the admin

2009-12-14 Thread Zeynel
I found this thread: 
http://groups.google.com/group/django-users/msg/11b034152c9dff1a
Does anyone have more details on urlize?

On Dec 14, 1:16 pm, Zeynel <azeyn...@gmail.com> wrote:
> In my models I have this field
>
> firm_url = models.CharField('Bio', max_length=200)
>
> that should have a link to the website where the lawyer bio is. This
> is in the admin. I thought that
>
> firm_url = models.URLField('Bio', max_length=200)
>
> would make the url appear as a link; but it doesn't; documentation
> says URLField is a CharField. So how do I make this url clickable in
> the admin? Thanks.

--

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.




Clickable url in the admin

2009-12-14 Thread Zeynel
In my models I have this field

firm_url = models.CharField('Bio', max_length=200)

that should have a link to the website where the lawyer bio is. This
is in the admin. I thought that

firm_url = models.URLField('Bio', max_length=200)

would make the url appear as a link; but it doesn't; documentation
says URLField is a CharField. So how do I make this url clickable in
the admin? Thanks.

--

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.