Ticket #33703: test.py

File test.py, 1.4 KB (added by Maxim Danilov, 3 years ago)

example which works for me on django 4.01

Line 
1from django.db import models
2from django.contrib.admin import ModelAdmin
3
4
5class 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
10class MyModelAdmin1(ModelAdmin):
11
12 fields = ('title', )
13
14
15class 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
44print(MyModelAdmin1(MyModel, None).get_fields(None))
45print(MyModelAdmin2(MyModel, None).get_fields(None))
Back to Top