Custom fieldset settings for django admin with groups access
# models.py
import custom_fields
class Test(models.Model):
class FieldCategory(custom_fields.CategoryChoices):
category_a = custom_fields.CategoryLabel('category_a') # 1
category_b = custom_fields.CategoryLabel(
'category_b',
hidden_for_superuser=True
allowed_groups=['Group names who can see and edit']
)
test_row_1 = custom_fields.CharField(max_length=40, category=FieldCategory.category_a)
test_row_2 = custom_fields.CharField(max_length=40, category=FieldCategory.category_a)
test_row_3 = custom_fields.CharField(max_length=40, category=FieldCategory.category_b)
test_row_4 = custom_fields.CharField(max_length=40, category=FieldCategory.category_b)
# admin.py
import custom_fields
class TestAdmin(custom_fields.ModelAdminMixin, admin.ModelAdmin):
readonly_fields = ("extra_field", )
extra_fieldsets = {
Test.FieldCategory.category_a: [
"extra_field", # For extra fields outside of model
]
} # optional
def extra_field(self, obj: Test):
return f"#{obj.id}"
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-custom-fieldsets-0.0.1.tar.gz.
File metadata
- Download URL: django-custom-fieldsets-0.0.1.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e11d6a4bcdf77f0fbbfeeb805f6b5382ce69bcdd19ac76891c64bd7ce65aa3fc
|
|
| MD5 |
a61fa6113fb8cda8eea3c24a07d99fa6
|
|
| BLAKE2b-256 |
9f9ebaa287dba53647ac1b5362071330d2a9bd2c2f7cd4f1e8b8f9b99ab35c7c
|