0

I have situation where I have lots of different type of content on my website such as blogs, posts, articles and so on. I have a made a favorite class for each such model, where I store the people who have set a particular instance of that model as there favorite.

Below given are the models

# For storing user favorites -- blogs
class favorite(models.Model):

    user = models.ForeignKey(User)
    entry = models.ForeignKey(Entry)
    created = models.DateTimeField()

    def save(self, *args, **kwargs):
        if not self.id:
            self.created = datetime.datetime.now()
        super(favorite, self).save(*args, **kwargs)

# For storing user favorites -- Posts
class favorite_post(models.Model):

    user = models.ForeignKey(User)
    post = models.ForeignKey(Post)
    created = models.DateTimeField()

    def save(self, *args, **kwargs):
        if not self.id:
            self.created = datetime.datetime.now()
        super(favorite_post, self).save(*args, **kwargs)

As can be seen both the class have the same structure except that one field changes, which is a reference to the object which was liked. In my view, I get the object list from each of the tables. Now I want to merge these object_list into one list, sorted on the basis of created time.

Is there a way i can do this?

Sachin
  • 3,672
  • 9
  • 55
  • 96

0 Answers0