URLField limitations

11 views
Skip to first unread message

Cole Tuininga

unread,
Aug 21, 2006, 10:17:39 AM8/21/06
to django...@googlegroups.com
Hi folks - I'll preface this by saying that I'm a complete newbie,
writing my first Django app.

Partially for the experience, and partially driven by small need, I'm
implementing an inhouse version of tinyurl (http://www.tinyurl.com/).
The model is pretty simple - it looks like:

# Create your models here.
class ShortURL(models.Model):
tag = models.CharField(
maxlength = 10,
unique = True,
editable = False,
blank = False
)
url = models.URLField( unique = True )
created = models.DateTimeField( auto_now_add = True, editable = False )
ip_addy = models.IPAddressField( editable = False, blank = False )

I'm running into a couple problems.

1) The URLField type is being restricted to 200 characters. Is there
a reason for this? Can it be overridden?

2) The validator is enforcing that the URL must currently be active.
I want to use the check to make sure that the url is properly
formatted, but I don't want to enforce that the url must respond. Is
there a way to get around this with the default validation? Or will I
need to write my own validator that will check the syntax of the url?

Thanks in advance, and to the authors of and contributors to Django -
keep up the great work. It's much appreciated.

--
Cole Tuininga
http://www.tuininga.org/

James Bennett

unread,
Aug 21, 2006, 10:43:40 AM8/21/06
to django...@googlegroups.com
On 8/21/06, Cole Tuininga <cole.t...@gmail.com> wrote:
> 1) The URLField type is being restricted to 200 characters. Is there
> a reason for this? Can it be overridden?

Not really. URLField subclasses CharField (because that's how it goes
into the database), which means that no matter what there's going to
be a hard limit of around 250 characters enforced by the DB.

> 2) The validator is enforcing that the URL must currently be active.
> I want to use the check to make sure that the url is properly
> formatted, but I don't want to enforce that the url must respond. Is
> there a way to get around this with the default validation? Or will I
> need to write my own validator that will check the syntax of the url?

Use the 'verify_exists' argument, set to False, as explained in the docs:
http://www.djangoproject.com/documentation/model_api/#urlfield


--
"May the forces of evil become confused on the way to your house."
-- George Carlin

James Bennett

unread,
Aug 21, 2006, 10:45:44 AM8/21/06
to django...@googlegroups.com
Cut off while I was writing...

Anyway, what I was going to suggest was that if you need the ability
to take in URLs of arbitrarily extreme lengths, you're probably better
off using a TextField for the URL and using the 'validator_list'
argument to pass in validators which will check that it's a URL (e.g.,
the built-in 'isValidURL' validator).

Reply all
Reply to author
Forward
0 new messages