views:

41

answers:

2

Hello,

How can I find an image, depending on the text?

I have image model with keywords:

class Post(models.Model):
    image = ImageField(_('Image'), blank=True, upload_to='folder')
    keywords = models.CharField(_('Keywords'), max_length=80)

And model which will serve as the search for a suitable image

class TextSearch(models.Model):
    body = models.TextField(_('Text'))
A: 

Are you looking for something like this?

# Set to search for posts with keyword 'cute'
search = TextSearch(body="cute") 

# Go run the search
results = Post.objects.filter(keywords__contains=search.body)

This will give you every Post with the TextSearch's body in the keywords. If that's not what you want, you might want to check here for a full list of Django's QuerySet methods.

Scavenger
What to do if body is a big text?
PyOut
A: 

What to do if body is a big text?

PyOut