Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Load ForeignKey label instead of ID in Charfield [RSS Feed]

#1 Dec. 2, 2010 16:03:13

b.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Load ForeignKey label instead of ID in Charfield


Hello,

I'm using a ForeignKey in my model and a Charfield in my form, when I
save data everything works well but when I try to edit something, I
get the ForeignKey ID in the Charfield.

There is a way to display the label instead of the ID when editing an
entry ?

Thank you

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 2, 2010 16:39:58

w.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Load ForeignKey label instead of ID in Charfield


On Dec 2, 10:03 am, bnabilos <bnabi...@gmail.com> wrote:
> Hello,
>
> I'm using a ForeignKey in my model and a Charfield in my form, when I
> save data everything works well but when I try to edit something, I
> get the ForeignKey ID in the Charfield.
>
> There is a way to display the label instead of the ID when editing an
> entry ?
>
> Thank you

So, let me get this straight--you have a ForeignKey from one model to
another, and you are editing that field by letting users enter text?
If so, why? You should be using some type of choice field.

Wayne

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 2, 2010 16:58:15

b.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Load ForeignKey label instead of ID in Charfield


Hi,

Thank you for your answer. That's right, I'm using a ForeignKey from a
model to another and I'm allowing users to edit it by entring text.
It's for a school project, I've added a method in my form
(clean_field(self)) that creates and saves an object based on what the
user wrote. I did that to avoid opening a popup to create the
foreignkey and selecting it.

Now when I save my form, everything works fine but when I try to edit
an entry, the ForeignKey ID is displayed rather than the label.

Thank you for your help

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Dec. 2, 2010 17:12:43

w.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Load ForeignKey label instead of ID in Charfield


Well, I'm guessing that what is displayed is what the unicode method
returns for the model that the ForeignKey points to (can't remember
for sure offhand, but I know that the admin interface works that
way). Of course, it might also be changing the display because you're
putting it in a TextField instead of a ChoiceField.

The whole point of a ForeignKey is to store a relationship between two
objects from different models. I really don't see how you would be
gaining anything by having users edit this data via a TextField. If
you don't like the widget that a form uses by default to select the
other model instance, you can change that fairly easily.

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Load ForeignKey label instead of ID in Charfield [RSS Feed]

Board footer

Moderator control

Enjoy the 21st of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support