Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have found a solution where I can search for my Members by User.email, user.first_name, or user.last_name and get back Member records + child records - and still easily get back to the User record if I need to. The issue I was having was that I needed to be able to find my Members by User fields. Instead of modifying the User admin site (django's auth_user), I modified my Member admin site (Member being my extension of django's User).</p> <p><strong>admin.py</strong></p> <pre><code>from DjangoSite.ManageProducts.models import Member, SaleItem from django.contrib import admin class MemSalesInline(admin.TabularInline): model = SaleItem fk_name = 'Seller' class MemberAdmin(admin.ModelAdmin): list_display = ['__str__', 'lname', 'fname'] # fname, lname not sortable raw_id_fields = ("user",) #this allows search "members" by User fields. search_fields = ['user__email', 'user__last_name', 'user__first_name'] # include any child records here - child of "Member" inlines = [MemSalesInline,] admin.site.register(Member, MemberAdmin) </code></pre> <p><strong>models.py</strong></p> <pre><code>class Member(models.Model): MemberID = models.AutoField(primary_key=True) Country = models.ForeignKey(dmCountry, blank=True, null=True) # plus more additional member info... # these allow me to view email, last name and first name in the Member admin list page. def __str__(self): return "%s" % self.user.email def lname(self): return "%s" % self.user.last_name def fname(self): return "%s" % self.user.first_name </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload