I've been able to do this through the django environment shell, but hasn't worked on my actual site. Here is my model:
class ShoeReview(models.Model):
def __unicode__(self):
return self.title
title = models.CharField(max_length=200)
slug = models.SlugField(unique=True)
keywords = models.TextField()
author = models.ForeignKey(User, related_name='reviews')
pub_date = models.DateTimeField(auto_now_add='true')
Shoe = models.OneToOneField(Shoe) # make this select those without a shoe review in admin area
owner_reviews = OwnerReview.objects.filter(Shoe__name=Shoe)
I'm sure this is something silly, but I've been at it for around 6 hours. It's part of the reason I haven't slept in the last 18 :S
I'm trying to return all OwnerReview objects from the OwnerReview Model that match the current Shoe:
class OwnerReview(models.Model):
def __unicode__(self):
return self.comments
name = models.CharField(max_length=50)
pub_date = models.DateTimeField(auto_now_add='true')
Shoe = models.ForeignKey(Shoe)
email = models.EmailField()
rating = models.PositiveSmallIntegerField()
comments = models.CharField(max_length=500)
Here is what i'm trying to accomplish done through "python manage.py shell":
>>> from runningshoesreview.reviews.models import Shoe, OwnerReview
>>> ariake = Shoe.objects.get(pk=1)
>>> ariake.name
u'Ariake'
>>> owner_reviews_for_current_shoe = OwnerReview.objects.filter(Shoe__name=ariake.name)
>>> owner_reviews_for_current_shoe
[<OwnerReview: great pk shoe!>, <OwnerReview: good shoes, sometimes tear easy though.>]