Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Model field that links to a page ID, or external URL
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Diederik van der Boor  
View profile  
 More options Feb 13, 11:09 am
From: Diederik van der Boor <vdb...@gmail.com>
Date: Mon, 13 Feb 2012 17:09:17 +0100
Local: Mon, Feb 13 2012 11:09 am
Subject: Model field that links to a page ID, or external URL
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan Paugh  
View profile  
 More options Feb 13, 12:50 pm
From: Jonathan Paugh <jpa...@gmx.us>
Date: Mon, 13 Feb 2012 12:50:03 -0500
Local: Mon, Feb 13 2012 12:50 pm
Subject: Re: Model field that links to a page ID, or external URL
On 02/13/2012 11:09 AM, Diederik van der Boor wrote:

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diederik van der Boor  
View profile  
 More options Feb 14, 10:14 am
From: Diederik van der Boor <vdb...@gmail.com>
Date: Tue, 14 Feb 2012 16:14:03 +0100
Local: Tues, Feb 14 2012 10:14 am
Subject: Re: Model field that links to a page ID, or external URL

Op 13 feb. 2012, om 18:50 heeft Jonathan Paugh het volgende geschreven:

> 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+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

I'm reluctant to use such method, when the absolute URL changes, the links break.
With a "pageid://##" solution I dynamically get get_absolute_url() when it's read.

Also, this solution gives me another problem: the URL needs to be reversed to find the ID
which was used in the select box / raw_id_field to choose the model.

if the solution still involves storing the value in a string field,
I still prefer my solution of storing the ID over a copied URL.

Diederik


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »