Example #1
0
def home(request, pk=None):

    '''
    if pk:
        #city = City.objects.filter(id=pk).first()
        city = get_object_or_404(City, id=pk)
        context = {'object': city}
        return render(request, 'cities/detail.html', context)
    '''

    if request.method == 'POST':
        form = CityForm(request.POST)
        if form.is_valid():
            print(form.cleaned_data)
            form.save()

    form = CityForm()

    qs = City.objects.all()

    # пагинация
    lst = Paginator(qs, 2)
    page_number = request.GET.get('page')
    page_obj = lst.get_page(page_number)

    context = {'page_obj': page_obj, 'form': form}
    return render(request, 'cities/home.html', context)
Example #2
0
def index(request):
    if request.method == 'POST':
        form = CityForm(request.POST)
        if form.is_valid():
            form.save()
    form = CityForm()
    context = {'form': form}
    return render(request, 'cities/index.html', context)
Example #3
0
def home(request, pk=None):
    if request.method == 'POST':
        form = CityForm(request.POST)
        if form.is_valid():
            form.save()
    form = CityForm()
    qs = City.objects.all()
    lst = Paginator(qs, 2)
    page_number = request.GET.get('page')
    page_obj = lst.get_page(page_number)
    context = {'page_obj': page_obj, 'form': form}
    return render(request, 'cities/home.html', context)
Example #4
0
def home(request, pk=None):
    if request.method == 'POST':
        form = CityForm(request.POST or None)
        if form.is_valid():
            print(form.cleaned_data)
            form.save()
    if pk:
        # city = City.objects.filter(id=pk).first()
        # city = City.objects.get(id=pk)
        city = get_object_or_404(City, id=pk)
        context = {'object': city}
        return render(request, 'cities/detail.html', context)
    cities = City.objects.all()
    paginator = Paginator(cities, 2)
    page = request.GET.get('page')
    cities = paginator.get_page(page)
    form = CityForm()
    context = {'page_obj': cities, 'form': form}
    return render(request, 'cities/home.html', context)
Example #5
0
def home(request, pk=None):
    if request.method == 'POST':
        form = CityForm(request.POST)
        if form.is_valid():
            print(form.cleaned_data)
            form.save()

    # if pk:
    #     # city = City.objects.filter(id=pk).first()
    #     # city = City.objects.get(id=pk)
    #     city = get_object_or_404(City, id=pk)
    #     context = {'object': city}
    #     return render(request, 'cities/detail.html', context)
    #
    form = CityForm()

    qs = City.objects.all()
    context = {'obj_list': qs, 'form': form}
    return render(request, 'cities/home.html', context)