This is my models.py:
class Image(models.Model):
user = models.ForeignKey(User)
caption = models.CharField(max_length=300)
image = models.ImageField(upload_to=get_upload_file_name)
pub_date = models.DateTimeField(default=datetime.now)
class Meta:
ordering = ['-pub_date']
verbose_name_plural = ('Images')
def __unicode__(self):
return "%s - %s" % (self.caption, self.user.username)
class ProfilePic(Image):
pass
class BackgroundPic(Image):
pass
class Album(models.Model):
name = models.CharField(max_length=150)
def __unicode__(self):
return
self.name class Photo(Image):
album = models.ForeignKey(Album, default=3)
And this is another:
class UserProfile(models.Model):
user = models.OneToOneField(User)
permanent_address = models.TextField()
temporary_address = models.TextField()
profile_pic = models.ForeignKey(ProfilePic)
background_pic = models.ForeignKey(BackgroundPic)
def __unicode__(self):
return self.user.username
I can access the Parent class with its User object.
>>>m = User.objects.get(username='mika')
>>>m.image_set.all()
>>>[<Image: mika_photo - mika>, <Image: mika_pro - mika>, <Image: mika_bf - mika>]
But I can't access its child class with the User. I tried:
>>>m.Image.profilepic_set.all()
and
>>>m.image_set.profilpic.all()
and this
>>>m.profilepic_set.all()
AttributeError:'User' object has no attribute 'profilepic_set'
But all gave me errors! How do I access the child classes, so that I can add images from one class to another. Like copy one image from Photo to ProfilePic, or from ProfilePic to BackgroundPic and so. Or simply, how to add images for particular User in specific classes?
Please guide me to achieve the above mentioned. Will be much appreciated. Thank you.