Question

Debug show me that:

comments = Comment.get_for_intention(id)

is:

{QuerySet} Unable to get repr for class 'django.db.models.query.QuerySet'

Comment model:

class Comment(models.Model):
    user = models.ForeignKey(User)
    intention = models.ForeignKey(Intention)
    text = models.TextField()
    created = models.DateTimeField(default=datetime.datetime.now())

    @staticmethod
    def get_for_intention(intention_id):
        return Comment.objects.filter(intention=intention_id)[:10]

I have no idea what I am doing wrong. Could someone give me any advice?

Was it helpful?

Solution

I think problem is because of intention. it is foreign key and you want to use all intention object.

You should use

def get_fot_intention(self):
   return self.Intention.intention_id

if you want to take comments only you dont have to define get_fot_intention and you dont have to use intention_id , just use intention object. You can use this for example:

def intention_detail(request,slug=None):

    intention = get_object_or_404(Intention,slug=slug)
    comments = Comment.objects.filter(intention=intention) 

but you have to slug field in intention.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top