Thank you Javier, for some reason I cannot get it working.
Using your example, I noticed the return value is stripdomain, I am
assuming that function would be outside of the model?
Assuming the code you provided, I would expect that adding the code
below, directly above the class yourmodel definition, would work:
import urlparse
def stripdomain(url):
bits = urlparse.urlparse(url)
return bits[1]
However the domain is not stripped when querying as follows:
>>> url = yourmodel.objects.get(id=1)
>>> url.domain
u'http://yourdomain.com/'
Can you tell if I am missing something?
On Aug 24, 11:05 am, Javier Guerra <[email protected]> wrote:
> On Mon, Aug 24, 2009 at 1:01 PM, Merrick<[email protected]> wrote:
> > I know how to parse the URL but am drawing a blank on how to
> > accomplish this at the model level.
>
> add a function to the model, that returns the parsed field.
>
> class yourmodel (models.Model):
> ....
> domain = models.URLField(...)
> ....
> def strippeddoamin (self):
> return stripdomain(self.domain)
>
> --
> Javier
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---