My goal is to get a list of unique countries referenced through a table. My model has:
class Country(models.Model): Abbreviation = models.CharField(maxlength = 2, primary_key=True) Country = models.CharField(maxlength = 50) class TrainingEvent(models.Model): Country = models.ForeignKey(Country) Partner = models.ForeignKey(Partner) City = models.CharField(maxlength = 50) Course_Title = models.CharField(maxlength = 80) class EventDates(models.Model): TrainingEvent = models.ForeignKey(TrainingEvent) Event_Start = models.DateField(core = True) Event_Dates = models.CharField(core = True, maxlength = 30) I only want a list of countries that are referenced for a TrainingEvent whose Event_Start__range=(begin,end) >>> eds = EventDates.objects.filter(Event_Start__range=(start,end) >>> eds [<EventDates: June 25th - 28th>, <EventDates: July 2nd - 5th>, <EventDates: July 23rd - 25th>, <EventDates: Aug 6th - 9th>, <EventDates: July 9th - 10th>, <EventDates: July 23rd - 24th>] >>> eds.values('TrainingEvent').distinct() [{'TrainingEvent': 1L}, {'TrainingEvent': 2L}] >>> eds.values('TrainingEvent.Country') FieldDoesNotExist: EventDates has no field named 'TrainingEvent.Country' >>> eds.values('TrainingEvent_Country') FieldDoesNotExist: EventDates has no field named 'TrainingEvent_Country' >>> eds.values('TrainingEvent__Country') FieldDoesNotExist: EventDates has no field named 'TrainingEvent__Country' Again, my goal is to be able to show each Country that has a TrainingEvent that has an Event_Start between start and end. There are probably many ways to get there. I'm very used to SQL and could do this in a heartbeat that way, but I want to learn the Django way. On a related note, I often would like to do something like: SELECT * FROM other_table WHERE some_value in ('a','b','c'); The way that seems logical to me is to do: values = TableName.objects.values('id').filter(...) t = OtherTable.objects.filter(TableName__in=values) I've tried several permutations of this and haven't found anything that works. What is the correct way to do this? --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---