Saturday, November 9, 2013

Get a set of objects from different models field names

Please have a look at my models.

    class BackgroundImage(models.Model):
        user = models.ForeignKey(User)
        image = models.ImageField(upload_to=get_upload_file_name)
        caption = models.CharField(max_length=200)
        pub_date = models.DateTimeField(default=datetime.now)

    class ProfilePicture(models.Model):
        user = models.ForeignKey(User)
        image = models.ImageField(upload_to=get_upload_file_name)
        caption = models.CharField(max_length=200)
        pub_date = models.DateTimeField(default=datetime.now)

    class Album(models.Model):
        user = models.ForeignKey(User)
        name = models.CharField(max_length=200)
        pub_date = models.DateTimeField(default=datetime.now)

        class Meta:
            ordering = ['-pub_date']
            verbose_name_plural = ('Albums')

        def __unicode__(self):
            return self.name

    class Photo(models.Model):
        user = models.ForeignKey(User)
         album = models.ForeignKey(Album, default=3)
        image = models.ImageField(upload_to=get_upload_file_name)
        caption = models.CharField(max_length=200)
        pub_date = models.DateTimeField(default=datetime.now)

How do I get all the images of Photo, ProfilePicture and BackgroundImage from their image field in one set. And then filter them by -pub_date to display in the template? Please help me out. Will be much much appreciated! Thank you.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHSNPWt1r_hu7bCwnCQi5otrmHeSMW4mVvfK24LXbq1gcu6Ktw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate