Skip to main content

Custom fieldset settings for django admin

Project description

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}"      

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-custom-fieldsets-0.0.1.tar.gz (12.6 kB view details)

Uploaded Source

File details

Details for the file django-custom-fieldsets-0.0.1.tar.gz.

File metadata

File hashes

Hashes for django-custom-fieldsets-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e11d6a4bcdf77f0fbbfeeb805f6b5382ce69bcdd19ac76891c64bd7ce65aa3fc
MD5 a61fa6113fb8cda8eea3c24a07d99fa6
BLAKE2b-256 9f9ebaa287dba53647ac1b5362071330d2a9bd2c2f7cd4f1e8b8f9b99ab35c7c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page