On 02/13/2012 11:09 AM, Diederik van der Boor wrote:
> Hi,
> 
> In CMS interfaces I generally encounter a problem with URL fields.
> In most situations, the following options need to be supported:
> - An URL to an external page  (Django's URLField can handle that)
> - An URL to an internal page (e.g. Django CMS)
> - An URL to an other model (e.g. article)
> 
> How can I reasonably store this information in a model field?
> I would love to store these values as foreign key, as it would allow more 
> querying options.
> 
> I've written a solution for this before using a forms.MultiValueField / 
> MultiWidget input,
> which did involve the ugly hack of saving the contents as string, using the 
> format:
> - http://...external-page/
> - pageid://##        -- the internal page
> - articleid://##      -- link to an article.
> This works, and did fit in the project deadline.
> However, I would like to improve upon this.
> 
> Does anyone have a suggestion on how to store the various information 
> properly?
> 
> Greetings,
> Diederik
> 
Each model supports a get_absolute_url(self) method, which allows you to
retrieve each object's url in whatever way you want, including pulling
values from self (i.e. the model object.). Returned urls are in serveral
formats; my prefered is '/full/path/to/article'.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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