Saturday, February 26, 2011

Re: searching a model in admin with data from a related model

Yes, as far as I know if CustomerId was changed to:

customer = models.ForeignKey(Customer)

You would be able to say:

search_fields = ['barcode', 'customer__first_name',
'customer__last_name']

...on your Tracker's ModelAdmin.

Cheers

On Feb 25, 5:54 pm, Bobby Roberts <tchend...@gmail.com> wrote:
> consider this model (only a portion of it):
>
> class Tracker (models.Model):
>         id = models.AutoField (primary_key=True)
>         Barcode = models.IntegerField(unique = True, blank=False)
>         OrderId = models.IntegerField(blank=False)
>         CustomerId = models.CharField (max_length=20, blank=False)
>        [[sniped]]
>
> when you view the Tracker model in /admin on the list page, there is a
> search box in the top right corner.  Is it possible to search on
> another model called Customer for Customer.firstname,
> customer.LastName?  If you notice we have CustomerId as a charfield...
> if we changed that to a foreign key, is it possible to search the
> Tracker model by customer firstname/lastname and if so, how?
>
> thanks in advance!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment