Monday, November 29, 2010

Re: Create an object before calling the save method

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-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.

No comments:

Post a Comment