Страницы, созданные из существующих php, заменяются на python и Django.
Существующий запрос
Select
l.lawyer_idx,
l.lawyer_email,
lp.lawyer_profile_path,
lp.lawyer_profile_name,
lc.lawyer_company_name,
lc.lawyer_company_address,
lc.lawyer_detail_address,
l.lawyer_agent
from lawyer l
left join lawyer_profile lp on l.lawyer_idx = lp.lawyer_idx
left join lawyer_company lc on l.lawyer_idx = lc.lawyer_idx
order by l.register_date desc;
Я создал каждую таблицу на models.py
models.py
class Lawyer(models.Model):
lawyer_idx = models.AutoField('ID', primary_key=True)
lawyer_email = models.CharField('E-mail', unique=True, max_length=200)
lawyer_agent = models.CharField(max_length=1, blank=True, null=True)
class Meta:
managed = False
db_table = 'lawyer'
class LawyerProfile(models.Model):
lawyer_idx = models.AutoField('ID', primary_key=True)
lawyer_profile_path = models.CharField(max_length=200, blank=True, null=True)
lawyer_profile_name = models.CharField(max_length=100, blank=True, null=True)
.................
class LawyerCompany(models.Model):
lawyer_idx = models.AutoField('ID', primary_key=True)
lawyer_company_name = models.CharField(max_length=100)
...............
Мы хотели бы поместить следующий запрос в часть list_display Django Admin.py. Есть ли способ показать данные, которые действительно были объединены в sql?
Admin.py
from django.contrib import admin
from .models import Lawyer, LawyerCompany, LawyerProfile
@admin.register(Lawyer)
class LawyerAdmin(admin.ModelAdmin):
list_per_page = 100
**list_display = ['lawyer_idx', 'lawyer_email',
'lawyer_agent', 'lawyer_profile_path', 'lawyer_profile_name', 'lawyer_company_name']**