Thursday, November 11, 2010

Add a create button for foreign keys(ModelForms)

I have the following models.py file:

class Account(models.Model):
name = models.CharField(max_length=30)
user = models.ForeignKey(User, related_name='account_creator')

class Category(models.Model):
name = models.CharField(max_length=30)
account = models.ForeignKey(Account, related_name='categories')

class Transaction(models.Model):
name = models.CharField(max_length=30)
...
category = models.ForeignKey(Category,
related_name='transactions', blank=True, null=True)
account = models.ForeignKey(Account, related_name='transactions')

In a view I've a modelform for the Transaction class, but the problem
with it is that I can't add a category or an account from this form.
I'd like to know how to add a "create button" to the view/form. The
django admin does this pretty well but I can't find how to use it.

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate