0

I am learning to use GeoDjango, and it is my understanding that a GeoManager() is needed to interact with GIS objects.

However, I was trying to build in some search functionality for my models. I found this old post that showed how to build a nifty little search manager using q objects like so:

class NewsPostManager(models.Manager):
    def search(self, search_terms):
        terms = [term.strip() for term in search_terms.split()]
        q_objects = []

        for term in terms:
            q_objects.append(Q(title__icontains=term))
            q_objects.append(Q(content__icontains=term))

        # Start with a bare QuerySet
        qs = self.get_query_set()

        # Use operator's or_ to string together all of your Q objects.
        return qs.filter(reduce(operator.or_, q_objects))

It is my understanding that this wouldn't work for GIS objects, as it doesn't invoke models.GeoManager(). Is there a way to extend models.GeoManager with this added functionality?

Adam Starrh
  • 6,428
  • 8
  • 50
  • 89

1 Answers1

1

You can add extra manager methods. In the case of geodjango you have to override the default manager (objects) with a GeoManager. You need to override models.GeoManager instead of models.Manager to have a custom manager on that case.

cdvv7788
  • 2,021
  • 1
  • 18
  • 26