Home > OS >  How to override admin.ModelAdmin class from site-packages?
How to override admin.ModelAdmin class from site-packages?

Time:07-06

i want to override help_text for some model in site-packages. but i obviously can't just change it in package because it will not be saved after updating packages and some other actions.

    crontab = models.ForeignKey(
        CrontabSchedule, on_delete=models.CASCADE, null=True, blank=True,
        verbose_name=_('crontab'), help_text=_('Use one of interval/crontab'),
    )

probably i have to create some app and override the whole thing in admin.py but i'm not sure it is a good practice.

also there is option with localize i consider but i still will have to create an app for that.

CodePudding user response:

You can create separate file/folder.

custom/admin.py

from django.contrib import admin

class CustomModelAdmin(admin.ModelAdmin):
    # Override function/properties

Then in your <app>/admin.py inherit from custom class you've created

from custom.admin import CustomModelAdmin

class ClassName(CustomModelAdmin):
    # Your code

CodePudding user response:

from django_celery_beat.models import PeriodicTask

PeriodicTask._meta.get_field('crontab').help_text = ('overriding text')

worked just fine.

  • Related