django-jet
django-jet copied to clipboard
get_changeform_initial_data not working
I have a model in Django:
class Office(BaseModelWithNameAddressMobile):
...
office_type = models.IntegerField(_("Office type"), choices=[(tag.value, _(tag.name)) for tag in OfficeType])
...
I am creating 5 different views in Admin Panel for this, one for each office_type. In the default admin panel, I was using the below code to set the value for office_type accordingly.
@admin.register(ZoneOffice)
class ZoneOfficeAdmin(OfficeAdmin):
def get_changeform_initial_data(self, request):
return {'office_type': OfficeType.ZONE.value}
def get_queryset(self, request):
return self.model.objects.filter(office_type=OfficeType.ZONE.value)
But, this stopped working when I moved my code to Django-jet.
Please take a look.
Thanks
from django.contrib import admin
from .models import Office, ZoneOffice
from jet.admin import CompactInline
class CustomOfficeAdmin(admin.ModelAdmin):
def get_changeform_initial_data(self, request):
initial = super().get_changeform_initial_data(request)
initial['office_type'] = OfficeType.ZONE.value
return initial
@admin.register(Office)
class OfficeAdmin(CustomOfficeAdmin):
pass
@admin.register(ZoneOffice)
class ZoneOfficeAdmin(CustomOfficeAdmin):
def get_queryset(self, request):
return self.model.objects.filter(office_type=OfficeType.ZONE.value)