Saturday, November 27, 2010

Create an object before calling the save method

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