Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango - Get a set of objects from different models field names
    primarykey
    data
    text
    <p>Please have a look at my models.</p> <pre><code>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) </code></pre> <p>How do I get all the images of <code>Photo</code>, <code>ProfilePicture</code> and <code>BackgroundImage</code> from their <code>image field</code> in one set. And then filter them by <code>-pub_date</code> to display in the template? Please help me out. Will be much much appreciated! Thank you.</p> <p><strong>Edit</strong></p> <p>N.B: I need <code>ProfilePicture</code> and <code>BackgroundImage</code> to work with the <code>UserProfile</code> like this:</p> <pre><code>from django.db import models from django.contrib.auth.models import User from profile_picture.models import ProfilePicture from background_image.models import BackgroundImage class UserProfile(models.Model): user = models.OneToOneField(User) permanent_address = models.TextField() temporary_address = models.TextField() profile_pic = models.ForeignKey(ProfilePicture) background_pic = models.ForeignKey(BackgroundImage) def __unicode__(self): return self.user.username User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0]) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload