| | 135 | |
|---|
| | 136 | def fieldsets(self, request): |
|---|
| | 137 | """ |
|---|
| | 138 | Generator that yields Fieldset objects for use on add and change admin |
|---|
| | 139 | form pages. |
|---|
| | 140 | |
|---|
| | 141 | This default implementation looks at self.fields, but subclasses can |
|---|
| | 142 | override this implementation and do something special based on the |
|---|
| | 143 | given HttpRequest object. |
|---|
| | 144 | """ |
|---|
| | 145 | if self.fields is None: |
|---|
| | 146 | default_fields = [f.name for f in self.opts.fields + self.opts.many_to_many if f.editable and not isinstance(f, models.AutoField)] |
|---|
| | 147 | yield Fieldset(fields=default_fields) |
|---|
| | 148 | else: |
|---|
| | 149 | for name, options in self.fields: |
|---|
| | 150 | yield Fieldset(name, options['fields'], classes=options.get('classes'), description=options.get('description')) |
|---|
| | 151 | |
|---|
| | 152 | def fieldsets_add(self, request): |
|---|
| | 153 | "Hook for specifying Fieldsets for the add form." |
|---|
| | 154 | for fs in self.fieldsets(request): |
|---|
| | 155 | yield fs |
|---|
| | 156 | |
|---|
| | 157 | def fieldsets_change(self, request, object_id): |
|---|
| | 158 | "Hook for specifying Fieldsets for the change form." |
|---|
| | 159 | for fs in self.fieldsets(request): |
|---|
| | 160 | yield fs |
|---|