Opened 9 years ago
Closed 4 years ago
#26607 closed New feature (fixed)
Add a hook to customize the admin's formsets parameters
Reported by: | David Sanders | Owned by: | Manav Agarwal |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | admin inline formset initial |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
New feature that adds a method on InlineModelAdmin for providing initial data for the inline formset. By default there is no implementation, although one could be implemented to use GET
parameters like get_changeform_initial_data
, but it wouldn't be trivial due to the list nature of formset initial data.
Change History (16)
comment:1 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 8 years ago
Patch needs improvement: | set |
---|
comment:3 by , 8 years ago
Summary: | Add InlineModelAdmin.get_formset_initial_data(). → Add a hook to customize the admin's formsets parameters |
---|
I think we should add a more general customization hook that allows customizing the parameters passed to the formset initialization (which includes initial data). That could also allow the use case of #27240 which requires adding form_kwargs': {'request': request}
to formset_params
.
comment:4 by , 4 years ago
Owner: | removed |
---|---|
Status: | new → assigned |
comment:5 by , 4 years ago
Owner: | set to |
---|
comment:6 by , 4 years ago
Considering the model and admin as defined below.
models.py
class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): author = models.ForeignKey(Author, on_delete=models.CASCADE) name = models.CharField(max_length=100)
admin.py
class BookInline(admin.StackedInline): model = Book class AuthorAdmin(admin.ModelAdmin): inlines = [ BookInline, ] admin.site.register(Author, AuthorAdmin)
Is it a good idea to pass the initial vales of bookinline fields by using get request in such a way like
http://127.0.0.1:8000/admin/polls/author/add/?name=Author_name&book_1_name=book1_name_value&book_2_name=book2_name_value
Example:
http://127.0.0.1:8000/admin/polls/author/add/?name=william_shakespeare&book_1_name=Hamlet&book_2_name=Romeo_and_Juliet
Please update me if the idea seems fine so that I may create a PR in order to solve the issue.
comment:7 by , 4 years ago
Needs documentation: | set |
---|---|
Needs tests: | set |
Patch needs improvement: | unset |
comment:8 by , 4 years ago
Patch needs improvement: | set |
---|
comment:9 by , 4 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
comment:10 by , 4 years ago
Patch needs improvement: | unset |
---|
comment:11 by , 4 years ago
Needs documentation: | set |
---|
comment:12 by , 4 years ago
Needs documentation: | unset |
---|
comment:14 by , 4 years ago
Patch needs improvement: | unset |
---|
comment:15 by , 4 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Currently the PR has merge conflicts