from django.shortcuts import render
from django.http import HttpResponse

from .models import User


def homepage(request):
    return render(request, "index.html", {})


def search(request, name):
    members = User.objects.filter(first_name__icontains=name) or \
        User.objects.filter(last_name__icontains=name) or \
        User.objects.filter(username__icontains=name)

    json_data = [dict(
        id=member.id,
        full_name=' '.join([member.first_name, member.last_name]))
                for member in members]

    return HttpResponse(json_data, mimetype='application/json')

from django.shortcuts import render
from django.http import HttpResponse

from hackfmi.utils import json_view
from .models import User


def homepage(request):
    return render(request, "index.html", {})


@json_view
def search(request, name):
    members = User.objects.filter(first_name__icontains=name) or \
        User.objects.filter(last_name__icontains=name) or \
        User.objects.filter(username__icontains=name)

    json_data = [dict(
        id=member.id,
        full_name=' '.join([member.first_name, member.last_name]))
                for member in members]

    return json_data
Add view for searching users and return json format
Add view for searching users and return json format

  from django.shortcuts import render
  from django.http import HttpResponse
  
+ from hackfmi.utils import json_view
  from .models import User
  
  
  def homepage(request):
      return render(request, "index.html", {})
  
  
+ @json_view
  def search(request, name):
      members = User.objects.filter(first_name__icontains=name) or \
          User.objects.filter(last_name__icontains=name) or \
          User.objects.filter(username__icontains=name)
  
      json_data = [dict(
          id=member.id,
          full_name=' '.join([member.first_name, member.last_name]))
                  for member in members]
  
+     return json_data
-     return HttpResponse(json_data, mimetype='application/json')
- 
Add view for searching users and return json format
## Code Before:
from django.shortcuts import render
from django.http import HttpResponse

from .models import User


def homepage(request):
    return render(request, "index.html", {})


def search(request, name):
    members = User.objects.filter(first_name__icontains=name) or \
        User.objects.filter(last_name__icontains=name) or \
        User.objects.filter(username__icontains=name)

    json_data = [dict(
        id=member.id,
        full_name=' '.join([member.first_name, member.last_name]))
                for member in members]

    return HttpResponse(json_data, mimetype='application/json')

## Instruction:
Add view for searching users and return json format
## Code After:
from django.shortcuts import render
from django.http import HttpResponse

from hackfmi.utils import json_view
from .models import User


def homepage(request):
    return render(request, "index.html", {})


@json_view
def search(request, name):
    members = User.objects.filter(first_name__icontains=name) or \
        User.objects.filter(last_name__icontains=name) or \
        User.objects.filter(username__icontains=name)

    json_data = [dict(
        id=member.id,
        full_name=' '.join([member.first_name, member.last_name]))
                for member in members]

    return json_data