Hi, Thanks for advice Malcolm!
I feel a sample would save some time to other people. Time that i had to spend. class OnlyRealProfileSQL: def get_sql(*args): #select name from django_content_type where app_label = 'users' and model != 'profile' and model like '%p rofile' return ({}, ['"django_content_type"."model" LIKE %s', '"django_content_type"."app_label" = %s','"django_content_type"."model" != %s'], ['%profile', 'users','profile']) # Create your models here. class Site(models.Model): name=models.CharField(maxlength=150) profile_module=models.ForeignKey(ContentType, limit_choices_to=OnlyRealProfileSQL()) On 7/13/06, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > On Thu, 2006-07-13 at 21:54 +0800, Russell Keith-Magee wrote: > > > > > > On 7/13/06, Kilian CAVALOTTI <[EMAIL PROTECTED]> wrote: > > > > Argh, bad news. Actually I asked the question because I'd like > > to use custom > > SQL in a 'limit_choices_to' option, in the admin interface. I > > can't figure > > how to proceed, since this option only takes a dictionary of > > lookup > > arguments, or Q objects. So I guess there's no way to use > > custom SQL > > in 'limit_choices_to', is it? > > > > Unfortunately, no. There is not currently a way to put custom SQL in > > limit_choices_to. > > > > The idea (allowing an extra() clause on the Q objects so that you can > > have extra customization in limit_choices_to) is reasonable enough, so > > it's probably worth lodging this as an enhancement request, so the > > idea isn't lost. However, I wouldn't bet on this being implemented any > > time soon (unless your itch gets the better of you, and you try your > > own hand at a fix). > > > > Otherwise, you're out of luck. Sorry :-( > > Actually there is another solution. You can create a custom Q class (the > "Q" class is defined in django.db.query). The get_sql() method of your > class has to return something in the right format, so it requires > understanding the return results from django.db.query.parse_lookup(). > It's not too hard to work out (putting a print into Q.get_sql() and > running one should be enough of a start). > > Malcolm > > > > > > Russ Magee %-) > > > > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---