#3345: Admin Search Fields From Related Models
------------------------------------+---------------------------------------
Reporter:  [EMAIL PROTECTED]  |       Owner:  adrian         
  Status:  new                      |   Component:  Admin interface
 Version:  0.95                     |    Keywords:                 
   Stage:  Unreviewed               |   Has_patch:  0              
------------------------------------+---------------------------------------
 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"

-- 
Ticket URL: <http://code.djangoproject.org/ticket/3345>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to