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):
namee = 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开发者_Python百科 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.
The django admin wraps the widget used for inputting with a wrapper class, called RelatedFieldWidgetWrapper
. I'm afraid you cannot really use it outside the admin, because it is bound very tightly to it (for generating the "add another" view).
精彩评论