1π
β
This is actually not hard. The add form is instantiated using request.GET
to set initial values, so all you need to do is put the appropriate value into your URL:
def add_book_link(self, instance):
if instance.id:
url = '%s?publisher=%d' % (reverse('admin:myapp_book_add'), instance.id)
else:
url = reverse('admin:myapp_book_add')
return mark_safe(u'<a href="{u}">Add</a>'.format(u=url))
Iβm generally in the habit of setting allow_tags
rather than using mark_safe
for admin fields.
π€Peter DeGlopper
Source:stackexchange.com