0

I have models:

class News(models.Model):
    title = ...
    content = ...
    creationdate = models.DateTimeField(default=datetime.now)
    [etc]

class Model_A(models.Model):
    name = ...
    info = ...
    news = models.ManyToManyfield(News)
    [etc]

class Model_B(models.Model):
    field_b = ...
    info = ...
    news = models.ManyToManyfield(News)
    [etc]

And I want to get news from model_a and model_b, sort by creationdate. How to do it?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nips
  • 13,162
  • 23
  • 65
  • 103

1 Answers1

0

Assume you have model_a_inst as one of objects of Model_A you can do

model_a_inst.news.all().order_by('creationdate')
Rohan
  • 52,392
  • 12
  • 90
  • 87
  • It's ok to get one queryset. I think op is looking for a way to concatenate two querysets. Perhaps this will help http://stackoverflow.com/a/434755/1344854 – gwaramadze Jan 28 '14 at 13:33