django_reverse_admin
django_reverse_admin copied to clipboard
How to respect both the 'fields' and the 'admin_class' attributes?
Hello,
If I write:
inline_type = 'tabular'
person_field_list = ('id', 'first_name', 'inix', 'last_name',
'birthday', 'zip_code', 'street', 'house_number', 'house_suffix',
'place', 'email', 'email_2', 'phone_number', 'phone_number_2')
inline_reverse = [{'field_name': 'old_person',
'fields': person_field_list,
'admin_class': PersonInline},
('new_person', {'fields': person_field_list,
'admin_class': PersonInline})
]
Then for old_person it ignores the field list and shows all the fields. But for new_person it does show the correct fields but it ignores the admin_class (i think) because it is still showing the delete checkbox.
Am I missing something?
Context:
class PotentialPersonDuplicate(models.Model):
old_person = models.ForeignKey(Person, related_name='possible_newer_duplicates', on_delete=models.CASCADE)
new_person = models.ForeignKey(Person, related_name='possible_older_duplicates', on_delete=models.CASCADE)
class PersonInline(admin.TabularInline):
model = Person
def has_delete_permission(self, request, obj=None):
return False
I'm working with Django 4.2.3
I just had the same problem and ended up doing something like (following the proposed example):
class PotentialPersonDuplicateAdmin(ReverseModelAdmin):
inline_type = 'tabular'
inline_reverse = [{'field_name': 'old_person',
'admin_class': PersonInline},
{'field_name': 'new_person',
'admin_class': PersonInline},
]
class PersonInline(admin.TabularInline):
model = Person
fields = ('id', 'first_name', 'inix', 'last_name',
'birthday', 'zip_code', 'street', 'house_number', 'house_suffix',
'place', 'email', 'email_2', 'phone_number', 'phone_number_2')
def has_delete_permission(self, request, obj=None):
return False
But it would be great to be able to use the inline_reverse specification (also, having the can_delete flag would be perfect to accomplish this goal) without subclassing one of the built-in InlineModelAdmin classes:
class PotentialPersonDuplicateAdmin(ReverseModelAdmin):
inline_type = 'tabular'
person_field_list = ('id', 'first_name', 'inix', 'last_name',
'birthday', 'zip_code', 'street', 'house_number', 'house_suffix',
'place', 'email', 'email_2', 'phone_number', 'phone_number_2')
inline_reverse = [{'field_name': 'old_person',
'fields': person_field_list,
'can_delete': False},
{'field_name': 'new_person',
'fields': person_field_list,
'can_delete': False},
]