prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Tokenize person lookup to work with "name last_name"
  `lookups.PersonLookup` won't show 'Piotr Banaszkiewicz' for 'Piotr Ban' input – because it only looks up `personal` or `family` or `email`…
  
  
  </issue>
  <code>
  [start of workshops/lookups.py]
  1 from django.contrib.auth.models import Group
  2 from django.db.models import Q
  3 
  4 from selectable.base import ModelLookup
  5 from selectable.registry import registry
  6 from selectable.decorators import login_required
  7 
  8 from workshops import models
  9 
  10 
  11 @login_required
  12 class EventLookup(ModelLookup):
  13     model = models.Event
  14     search_fields = ('slug__icontains', )
  15 
  16 
  17 @login_required
  18 class HostLookup(ModelLookup):
  19     model = models.Host
  20     search_fields = (
  21         'domain__icontains',
  22         'fullname__icontains'
  23     )
  24 
  25 
  26 @login_required
  27 class PersonLookup(ModelLookup):
  28     model = models.Person
  29     search_fields = (
  30         'personal__icontains',
  31         'family__icontains',
  32         'email__icontains',
  33         'username__icontains'
  34     )
  35 
  36 
  37 @login_required
  38 class AdminLookup(ModelLookup):
  39     """The same as PersonLookup, but allows only to select administrators.
  40 
  41     Administrator is anyone with superuser power or in "administrators" group.
  42     """
  43     model = models.Person
  44     search_fields = (
  45         'personal__icontains',
  46         'family__icontains',
  47         'email__icontains',
  48         'username__icontains'
  49     )
  50 
  51     def get_query(self, request, term):
  52         results = super().get_query(request, term)
  53         admin_group = Group.objects.get(name='administrators')
  54         results = results.filter(
  55             Q(is_superuser=True) | Q(groups__in=[admin_group])
  56         )
  57         return results
  58 
  59 
  60 @login_required
  61 class AirportLookup(ModelLookup):
  62     model = models.Airport
  63     search_fields = (
  64         'iata__icontains',
  65         'fullname__icontains'
  66     )
  67 
  68 
  69 registry.register(EventLookup)
  70 registry.register(HostLookup)
  71 registry.register(PersonLookup)
  72 registry.register(AdminLookup)
  73 registry.register(AirportLookup)
  74
  [end of workshops/lookups.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/workshops/lookups.py b/workshops/lookups.py
  --- a/workshops/lookups.py
  +++ b/workshops/lookups.py
  @@ -1,3 +1,7 @@
  +from functools import reduce
  +import operator
  +import re
  +
   from django.contrib.auth.models import Group
   from django.db.models import Q
   
  @@ -33,6 +37,32 @@
           'username__icontains'
       )
   
  +    def get_query(self, request, term):
  +        """Override this method to allow for additional lookup method: """
  +        # original code from selectable.base.ModelLookup.get_query:
  +        qs = self.get_queryset()
  +        if term:
  +            search_filters = []
  +            if self.search_fields:
  +                for field in self.search_fields:
  +                    search_filters.append(Q(**{field: term}))
  +
  +            # tokenizing part
  +            tokens = re.split('\s+', term)
  +            if len(tokens) == 2:
  +                name1, name2 = tokens
  +                complex_q = (
  +                    Q(personal__icontains=name1) & Q(family__icontains=name2)
  +                ) | (
  +                    Q(personal__icontains=name2) & Q(family__icontains=name1)
  +                )
  +                search_filters.append(complex_q)
  +
  +            # this is brilliant: it applies OR to all search filters
  +            qs = qs.filter(reduce(operator.or_, search_filters))
  +
  +        return qs
  +
   
   @login_required
   class AdminLookup(ModelLookup):
  
verification_info: {"golden_diff": "diff --git a/workshops/lookups.py b/workshops/lookups.py\n--- a/workshops/lookups.py\n+++ b/workshops/lookups.py\n@@ -1,3 +1,7 @@\n+from functools import reduce\n+import operator\n+import re\n+\n from django.contrib.auth.models import Group\n from django.db.models import Q\n \n@@ -33,6 +37,32 @@\n         'username__icontains'\n     )\n \n+    def get_query(self, request, term):\n+        \"\"\"Override this method to allow for additional lookup method: \"\"\"\n+        # original code from selectable.base.ModelLookup.get_query:\n+        qs = self.get_queryset()\n+        if term:\n+            search_filters = []\n+            if self.search_fields:\n+                for field in self.search_fields:\n+                    search_filters.append(Q(**{field: term}))\n+\n+            # tokenizing part\n+            tokens = re.split('\\s+', term)\n+            if len(tokens) == 2:\n+                name1, name2 = tokens\n+                complex_q = (\n+                    Q(personal__icontains=name1) & Q(family__icontains=name2)\n+                ) | (\n+                    Q(personal__icontains=name2) & Q(family__icontains=name1)\n+                )\n+                search_filters.append(complex_q)\n+\n+            # this is brilliant: it applies OR to all search filters\n+            qs = qs.filter(reduce(operator.or_, search_filters))\n+\n+        return qs\n+\n \n @login_required\n class AdminLookup(ModelLookup):\n", "issue": "Tokenize person lookup to work with \"name last_name\"\n`lookups.PersonLookup` won't show 'Piotr Banaszkiewicz' for 'Piotr Ban' input \u2013 because it only looks up `personal` or `family` or `email`\u2026\n\n", "before_files": [{"content": "from django.contrib.auth.models import Group\nfrom django.db.models import Q\n\nfrom selectable.base import ModelLookup\nfrom selectable.registry import registry\nfrom selectable.decorators import login_required\n\nfrom workshops import models\n\n\n@login_required\nclass EventLookup(ModelLookup):\n    model = models.Event\n    search_fields = ('slug__icontains', )\n\n\n@login_required\nclass HostLookup(ModelLookup):\n    model = models.Host\n    search_fields = (\n        'domain__icontains',\n        'fullname__icontains'\n    )\n\n\n@login_required\nclass PersonLookup(ModelLookup):\n    model = models.Person\n    search_fields = (\n        'personal__icontains',\n        'family__icontains',\n        'email__icontains',\n        'username__icontains'\n    )\n\n\n@login_required\nclass AdminLookup(ModelLookup):\n    \"\"\"The same as PersonLookup, but allows only to select administrators.\n\n    Administrator is anyone with superuser power or in \"administrators\" group.\n    \"\"\"\n    model = models.Person\n    search_fields = (\n        'personal__icontains',\n        'family__icontains',\n        'email__icontains',\n        'username__icontains'\n    )\n\n    def get_query(self, request, term):\n        results = super().get_query(request, term)\n        admin_group = Group.objects.get(name='administrators')\n        results = results.filter(\n            Q(is_superuser=True) | Q(groups__in=[admin_group])\n        )\n        return results\n\n\n@login_required\nclass AirportLookup(ModelLookup):\n    model = models.Airport\n    search_fields = (\n        'iata__icontains',\n        'fullname__icontains'\n    )\n\n\nregistry.register(EventLookup)\nregistry.register(HostLookup)\nregistry.register(PersonLookup)\nregistry.register(AdminLookup)\nregistry.register(AirportLookup)\n", "path": "workshops/lookups.py"}]}