# Path: listing/models.py
# class Neighbourhood(models.Model):
#     city = ParentalKey(City, related_name='neighbourhoods')
#     name = models.CharField(max_length=255)
#     slug = models.SlugField(max_length=255)
# 
#     panels = [
#         FieldPanel('city'),
#         FieldPanel('name'),
#         FieldPanel('slug'),
#     ]
# 
#     class Meta:
#         ordering = ('slug',)
#         verbose_name = 'bairro'
#         verbose_name_plural = 'bairros'
# 
#     def __str__(self):
#         return self.name
# 
# class Condominium(models.Model):
#     city = ParentalKey(City, related_name='condominiums')
#     name = models.CharField(max_length=255)
#     slug = models.SlugField(max_length=255)
# 
#     class Meta:
#         ordering = ('slug',)
#         verbose_name = 'condomínio'
#         verbose_name_plural = 'condomínios'
# 
#     def __str__(self):
#         return self.name


import json
from django.http import HttpResponse
from django.template.defaultfilters import slugify
from listing.models import Neighbourhood, Condominium




def neighbourhoods(request):
    city_id = request.GET.get('city', None)
    term = slugify(request.GET.get('term', ''))

    results = Neighbourhood.objects.filter(
        city__id=city_id,
        slug__contains=term,
    ).values_list('id', 'name')

    results = [{'id': r[0], 'text': r[1]} for r in results]

    return HttpResponse(content=json.dumps(results),
                        content_type='application/json')


def condominiums(request):
    city_id = request.GET.get('city', None)
    term = slugify(request.GET.get('term', ''))


# Path: listing/models.py
# class Neighbourhood(models.Model):
#     city = ParentalKey(City, related_name='neighbourhoods')
#     name = models.CharField(max_length=255)
#     slug = models.SlugField(max_length=255)
# 
#     panels = [
#         FieldPanel('city'),
#         FieldPanel('name'),
#         FieldPanel('slug'),
#     ]
# 
#     class Meta:
#         ordering = ('slug',)
#         verbose_name = 'bairro'
#         verbose_name_plural = 'bairros'
# 
#     def __str__(self):
#         return self.name
# 
# class Condominium(models.Model):
#     city = ParentalKey(City, related_name='condominiums')
#     name = models.CharField(max_length=255)
#     slug = models.SlugField(max_length=255)
# 
#     class Meta:
#         ordering = ('slug',)
#         verbose_name = 'condomínio'
#         verbose_name_plural = 'condomínios'
# 
#     def __str__(self):
#         return self.name


# Path: dashboard/views.py
import json
from django.http import HttpResponse
from django.template.defaultfilters import slugify
from listing.models import Neighbourhood, Condominium





def neighbourhoods(request):
    city_id = request.GET.get('city', None)
    term = slugify(request.GET.get('term', ''))

    results = Neighbourhood.objects.filter(
        city__id=city_id,
        slug__contains=term,
    ).values_list('id', 'name')

    results = [{'id': r[0], 'text': r[1]} for r in results]

    return HttpResponse(content=json.dumps(results),
                        content_type='application/json')


def condominiums(request):
    city_id = request.GET.get('city', None)
    term = slugify(request.GET.get('term', ''))


    results = Condominium.objects.filter(