Opened 18 years ago

Last modified 18 years ago

#3345 closed

Admin Search Fields From Related Models — at Initial Version

Reported by: rfreitag@… Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm trying to in the Admin Change List Form have the ability to search records via information from a related model.

Example
When in case_files I would like to search by Company Name, this information is stored in a separate object.

Can this be possible? Below is a sample of the models.py

Regards

class company_record(models.Model):

midas_number = models.CharField(maxlength=10, verbose_name='Midas Number')
company_name = models.CharField(maxlength=200, verbose_name='Company Name')
midas_parent = models.CharField(maxlength=10, verbose_name='Midas Parent Member Number')
parent_name = models.CharField(maxlength=200, verbose_name='Parent Company Name')
company_status = models.CharField(maxlength=100, verbose_name='Member Current Status')
company_cat = models.CharField(maxlength=10, verbose_name='Company Category')
def str(self):

return self.midas_number + " - " + self.company_name

class Admin:

pass
list_display = ('midas_number', 'company_name', 'midas_parent', 'parent_name', 'company_status', 'company_cat')
list_display_links = ('midas_number', 'company_name')
list_filter = ('company_cat', 'company_status')
search_fields = company_name

class Meta:

verbose_name = "Company Record"

class case_file(models.Model):

midas_number_id = models.AutoField(primary_key=True)
midas_number = models.ForeignKey(company_record, edit_inline=models.STACKED, num_in_admin=1, verbose_name="Company Name")
fileid = models.CharField(maxlength=10, core=True, primary_key=True, verbose_name='File ID')
file_state = models.CharField(maxlength=3, core=True, verbose_name='State')
file_status = models.CharField(maxlength=10, core=True, verbose_name='File Current Status')
file_open_date = models.DateField('File Open Date', core=True)
file_close_date = models.DateField('File Close Date', core=True)
owning_officer = models.CharField(maxlength=200, core=True, verbose_name='"Owning" Officer')
owning_dept = models.CharField(maxlength=200, core=True, verbose_name='"Owning" Department')
nature_of_matter = models.CharField(maxlength=200, core=True, verbose_name='Nature Of Matter')
destroy_date = models.DateField('Destroy Date', core=True)
purchase_order = models.CharField(maxlength=50, core=True, verbose_name='Purchase Order#')
document_desc = models.CharField(maxlength=200, core=True, verbose_name='Description of Document')

class Admin:

fields = (

('File Status Details', {'fields': ('midas_number', 'fileid', 'file_state', 'file_status', 'file_open_date', 'file_close_date', 'destroy_date')}),
('File Details', {'fields': ('owning_officer', 'owning_dept', 'nature_of_matter', 'purchase_order', 'document_desc')}),

)

list_select_related = True
search_fields = ['fileid', 'owning_officer', 'midas_number_id']
list_display = ('midas_number', 'fileid', 'owning_officer', 'owning_dept', 'document_desc', 'file_status' )
list_display_links = ('midas_number', 'fileid')
list_filter = ('owning_officer', 'owning_dept', 'nature_of_matter', 'file_status', 'file_open_date' )

class Meta:

verbose_name = "Case File"

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top