Python django.contrib.admin.register() Examples

The following are 7 code examples for showing how to use django.contrib.admin.register(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.contrib.admin , or try the search function .

Example 1
Project: clist   Author: aropan   File: admin.py    License: Apache License 2.0 6 votes vote down vote up
def admin_register(*args, **kwargs):
    def _model_admin_wrapper(admin_class):
        admin_class = admin.register(*args, **kwargs)(admin_class)

        model = next(iter(args))
        if BaseModel in model.__bases__:
            autocomplete_fields = getattr(admin_class, 'autocomplete_fields', None)
            if autocomplete_fields is not None:
                autocomplete_fields = list(autocomplete_fields)
                for field in model._meta.get_fields():
                    if field.name in autocomplete_fields:
                        continue
                    if isinstance(field, models.fields.related.RelatedField):
                        autocomplete_fields.append(field.name)
                setattr(admin_class, 'autocomplete_fields', autocomplete_fields)

        return admin_class
    return _model_admin_wrapper 
Example 2
Project: django-ai   Author: math-a3k   File: admin.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def get_form(self, request, obj=None, **kwargs):  # pragma: no cover
        # Save obj reference in the request for future processing in Inline
        request._obj_ = obj
        form = super(BayesianNetworkAdmin, self).get_form(request, obj,
                                                          **kwargs)
        form.base_fields["metadata"].widget.attrs["disabled"] = "disabled"
        return(form)

# @admin.register(BayesianNetworkNode)
# class BayesianNetworkNodeAdmin(admin.ModelAdmin):
#     pass


# @admin.register(BayesianNetworkEdge)
# class BayesianNetworkNodeEdge(admin.ModelAdmin):
#     pass 
Example 3
Project: django_microsoft_auth   Author: AngellusMortis   File: admin.py    License: MIT License 5 votes vote down vote up
def _register_admins():
    _do_both = config.MICROSOFT_AUTH_REGISTER_INACTIVE_ADMIN
    _login_type = config.MICROSOFT_AUTH_LOGIN_TYPE

    if admin.site.is_registered(MicrosoftAccount):
        admin.site.unregister(MicrosoftAccount)

    if admin.site.is_registered(XboxLiveAccount):
        admin.site.unregister(XboxLiveAccount)

    if _do_both or _login_type == LOGIN_TYPE_MA:
        admin.site.register(MicrosoftAccount, MicrosoftAccountAdmin)
    if _do_both or _login_type == LOGIN_TYPE_XBL:
        admin.site.register(XboxLiveAccount, XboxLiveAccountAdmin) 
Example 4
Project: django-localized-fields   Author: SectorLabs   File: test_admin.py    License: MIT License 5 votes vote down vote up
def test_model_admin(cls):
        """Tests whether :see:LocalizedFieldsAdminMixin mixin are works with
        admin.ModelAdmin."""

        @admin.register(cls.TestModel)
        class TestModelAdmin(LocalizedFieldsAdminMixin, admin.ModelAdmin):
            pass

        assert len(check_admin_app(apps.get_app_configs())) == 0 
Example 5
Project: django-localized-fields   Author: SectorLabs   File: test_admin.py    License: MIT License 5 votes vote down vote up
def test_stackedmodel_admin(cls):
        """Tests whether :see:LocalizedFieldsAdminMixin mixin are works with
        admin.StackedInline."""

        class TestModelStackedInline(
            LocalizedFieldsAdminMixin, admin.StackedInline
        ):
            model = cls.TestModel

        @admin.register(cls.TestRelModel)
        class TestRelModelAdmin(admin.ModelAdmin):
            inlines = [TestModelStackedInline]

        assert len(check_admin_app(apps.get_app_configs())) == 0 
Example 6
Project: django-localized-fields   Author: SectorLabs   File: test_admin.py    License: MIT License 5 votes vote down vote up
def test_tabularmodel_admin(cls):
        """Tests whether :see:LocalizedFieldsAdminMixin mixin are works with
        admin.TabularInline."""

        class TestModelTabularInline(
            LocalizedFieldsAdminMixin, admin.TabularInline
        ):
            model = cls.TestModel

        @admin.register(cls.TestRelModel)
        class TestRelModelAdmin(admin.ModelAdmin):
            inlines = [TestModelTabularInline]

        assert len(check_admin_app(apps.get_app_configs())) == 0 
Example 7
Project: lexpredict-contraxsuite   Author: LexPredict   File: admin.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def clean_username(self):
        username = self.cleaned_data["username"]
        try:
            User.objects.get(username=username)
        except User.DoesNotExist:
            return username
        raise forms.ValidationError(self.error_messages['duplicate_username'])


# @admin.register(User)