Отображение встроенных значений в модели администратора другого приложения
Я пытался разобраться с этим, но поскольку я не очень опытен в этом, я хотел спросить, есть ли способ отобразить значения из inline в model.admin другого приложения;
В моем случае:
accounts\admin.py:
@admin.register(models.Customer)
class CustomerAdmin(ImportExportModelAdmin, admin.ModelAdmin):
list_display = ('first_name', 'last_name', 'customer_subscription', 'company')
Здесь я хочу показать встроенные значения.
core\admin.py:
class ManageAddressInline(GenericStackedInline):
model = AssignAddress
class CustomCustomerAdmin(CustomerAdmin):
inlines = [ManageAddressInline]
admin.site.unregister(Customer)
admin.site.register(Customer, CustomCustomerAdmin)
address_reports\model.py:
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django_countries.fields import Country, CountryField
from accounts.models import Customer
class AssignAddressManager(models.Manager):
def get_tags_for(self, obj_type, obj_id):
content_type = ContentType.objects.get_for_model(obj_type)
return AssignAddress.objects \
.select_related('manage-address') \
.filter(
content_type=content_type,
object_id=obj_id
)
class ManageAddress(models.Model):
defined = models.ForeignKey(Customer, on_delete=models.CASCADE)
apartment_or_suite = models.CharField(max_length=255)
street = models.CharField(max_length=255)
city = models.CharField(max_length=255, null=True)
postal_code = models.CharField(max_length=20, blank=True)
country = CountryField()
class AssignAddress(models.Model):
objects = AssignAddressManager()
apartment_or_suite = models.CharField(max_length=255, null=True)
street = models.CharField(max_length=255, null=True)
city = models.CharField(max_length=255, null=True)
postal_code = models.CharField(max_length=255, null=True)
country = CountryField()
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey()
address_reports\admin.py:
from django.contrib import admin
from address_reports.models import ManageAddress
@admin.register(ManageAddress)
class ManageAddressAdmin(admin.ModelAdmin):
search_fields = ['defined', 'apartment_or_suite', 'street', 'city', 'postal_code', 'country']
list_display = ['defined', 'apartment_or_suite', 'street', 'city', 'postal_code', 'country']
Дополнительно, я бы хотел получить несколько лучших подходов, чем этот, и хотел бы иметь возможность управлять адресами для конкретного клиента на вкладке address_reports.