TL;DR: How can I add an "Add new" button for a ForeignKey in a ModelForm?
Long version: I'm using Django 1.7 for a project. I have these two Models in my models.py
class Client(models.Model):
name = models.CharField(max_length=100)
class Order(models.Model):
code = models.IntegerField()
client = models.ForeignKey(Client)
[some other non relevant fields are omitted]
I am using a ModelForm to populate the db with new orders, like this:
class OrderNewForm(forms.ModelForm):
class Meta:
model = Order
Django does quite a good job at adding a dropdown menu for the client field, populating it with entries taken from Client. Nevertheless, I'd like to have an "Add new client" link/button/whatever to add a brand new client at the same time I add a related Order.
Django admin does that automatically, adding a "+" button" that opens a popup, but I couldn't find an easy way to do that in a ModelForm like the one above. I read many questions here and links elsewhere, but nothing really helped me. Any idea about that?