Re: Load ForeignKey label instead of ID in Charfield

2010-12-02 Thread bnabilos
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 at 
http://groups.google.com/group/django-users?hl=en.



Load ForeignKey label instead of ID in Charfield

2010-12-02 Thread bnabilos
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Create an object before calling the save method

2010-11-29 Thread bnabilos
Hi,

Thank you for your answer.

I will explain what I want to do.

Let's say that we have Category and Article classes in our model, each
one has a title. To make this title reusable, I created another
application that will manage fields, I created the class Title and I
added it as foreignkey to Category and Article forms.

I switched the select box to an input field using raw_id_fields.

Now, when I create a category or an article, I have to select or write
a title, when this title exists, it works perfectly but when it
doesn't exist I want to create it before creating the category so it
can use it.

I tried to do that in the save method, in the pre_save signal and in
the clean method but I always get the error "Select a valid choice.
That choice is not one of the available choices."

I'm using a hard coded solution to create the title now, I want just
to see if it will work, these are the lines that I inserted in the
different methods to create the title before creating the category :

t = Title(title = "MyTitle")
t.save()

I tried to create a Category with MyTitle as title but I get the same
error, when I try to create another one using an existing title, it
works and the title "MyTitle" is created. That's mean that the
creation of the object happens after the form verification. What I
want is just doing this before. The title object should be created
before the verification.

Thank you very much 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 at 
http://groups.google.com/group/django-users?hl=en.



Create an object before calling the save method

2010-11-27 Thread bnabilos
Hello

I want to create an object in Django before calling the save method.
This object will be created from a ForeignKey Value, I've changed the
foreignkey field to look like an input field in order to write a value
instead of selecting it.

I have 2 classes in 2 different model files

class Category(models.Model):
title = models.ForeignKey(Title, verbose_name="Title")

and

class Title(models.Model):
title = models.CharField("Title", primary_key=True,
max_length=200)

When I create a category, I have to pick or write a title that already
exists in the database and when I try to create a category with a new
title I get this error :

Select a valid choice. That choice is not one of the available
choices.

What I want to do is creating a title based on what I write in the
ForeignKey field before creating the category so it can be used
immediately.

I tried to redefine the save method to save the title object before
saving the category but it didn't work.

Any help will be really appreciated.

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