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
  • 34,719
  • 24
  • 185
  • 251
Nips
  • 12,112
  • 22
  • 60
  • 99

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
  • 50,238
  • 11
  • 84
  • 85
  • 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