1 | from django.db import models
|
---|
2 | from django.contrib.admin import ModelAdmin
|
---|
3 |
|
---|
4 |
|
---|
5 | class MyModel(models.Model):
|
---|
6 | title = models.CharField('Meta Title of object', max_length=80, blank=True)
|
---|
7 | slug = models.CharField('Meta Slug of object', max_length=80, blank=True)
|
---|
8 |
|
---|
9 |
|
---|
10 | class MyModelAdmin1(ModelAdmin):
|
---|
11 |
|
---|
12 | fields = ('title', )
|
---|
13 |
|
---|
14 |
|
---|
15 | class MyModelAdmin2(ModelAdmin):
|
---|
16 |
|
---|
17 | fieldset = ('title', )
|
---|
18 |
|
---|
19 | # def get_fields(self, request, obj=None):
|
---|
20 | # """
|
---|
21 | # Hook for specifying fields.
|
---|
22 | # """
|
---|
23 | # if self.fields:
|
---|
24 | # return self.fields
|
---|
25 | # # _get_form_for_get_fields() is implemented in subclasses.
|
---|
26 | # form = self._get_form_for_get_fields(request, obj)
|
---|
27 | # return [*form.base_fields, *self.get_readonly_fields(request, obj)]
|
---|
28 |
|
---|
29 | # def _get_form_for_get_fields(self, request, obj):
|
---|
30 | # return self.get_form(request, obj, fields=None)
|
---|
31 |
|
---|
32 | # def get_form(self, request, obj=None, change=False, **kwargs):
|
---|
33 | # """
|
---|
34 | # Return a Form class for use in the admin add view. This is used by
|
---|
35 | # add_view and change_view.
|
---|
36 | # """
|
---|
37 | # if 'fields' in kwargs:
|
---|
38 | # fields = kwargs.pop('fields')
|
---|
39 | # else:
|
---|
40 | # fields = flatten_fieldsets(self.get_fieldsets(request, obj))
|
---|
41 | # ...
|
---|
42 |
|
---|
43 |
|
---|
44 | print(MyModelAdmin1(MyModel, None).get_fields(None))
|
---|
45 | print(MyModelAdmin2(MyModel, None).get_fields(None))
|
---|