Hi guys, I'm having a bit of trouble figuring this problem out. I have "Model A" with a set of fields, one of which is of type DateTimeField with auto_now_add=True, and the same in a second "Model B". Model B has a foreign key relationship to Model A.
ModelA: **** date_field_in_A = models.DateTimeField(auto_now_add=True) **** ModelB: **** model_a =models.ForeignKey(ModelA, related_name='related_name_to_model') owner = models.ForeignKey(User, 'related_name_to_owner') date_field_in_B = models.DateTimeField(auto_now_add=True) **** In a view I'm trying to retrieve a queryset of Model As filtered by a related name link to a field in Model B. model_a_set = ModelA.objects.filter(related_name_to_model__owner=request.user) Now, not all of the Model A's possess a related Model B *BUT* since A and B both possess a date, I want to order the whole lot of Model As by the date from Model B if it exists, and if not the date from Model A. I tried using the order_by with two sets of dates: .order_by('-related_name_to_model__date_field_in_B', '- date_field_in_A') However, this just produces a queryset that is partitioned into two separate date orderings. What I'm asking is if there is anyway to "intermix" the dates so that ALL of the Model As appear in date order, even if they do not have a related Model B date? If you need any clarification on what I'm trying to achieve, I'll gladly provide it! Thanks, Mike. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---