function action_on_change_city_sellector() {
let sel_city_item = event.srcElement.options[event.srcElement.selectedIndex];
console.log(sel_city_item)
// do code here
}
room_choices = {
'1':1,
'2':2,
'3':3,
'4':4,
'5':5,
'6':6,
'7':7,
'8':8,
'9':9,
'10':10,
}
stage_choices = {
'1':1,
'2':2,
'3':3,
'4':4,
'5':5,
'6':6,
'7':7,
'8':8,
'9':9,
}
price_choices = {
'100000':'$100,000',
'200000':'$200,000',
'300000':'$300,000',
'400000':'$400,000',
'500000':'$500,000',
'600000':'$600,000',
'700000':'$700,000',
'800000':'$800,000',
'900000':'$900,000',
'1000000':'$1M+',
}
def search(request):
queryset_list = Listing.objects.order_by('-list_date')
# Stage
if 'stage' in request.GET:
stage = request.GET['stage']
if stage:
queryset_list = queryset_list.filter(stage__iexact=stage)
# Rooms
if 'rooms' in request.GET:
rooms = request.GET['rooms']
if rooms:
queryset_list = queryset_list.filter(rooms__iexact=rooms)
# Price
if 'price' in request.GET:
price = request.GET['price']
if price:
queryset_list = queryset_list.filter(price__iexact=price)
# Keywords
if 'keywords' in request.GET:
keywords = request.GET['keywords']
if keywords:
queryset_list = queryset_list.filter(description__icontains=keywords)
context = {
'price_choices': price_choices,
'room_choices': room_choices,
'stage_choices': stage_choices,
'listings': queryset_list,
'values': request.GET
}
return render(request, 'listings/search.html', context)
from django.db import models
from datetime import datetime
from django.contrib.auth.models import User
class Listing(models.Model):
realtor = models.ForeignKey(Realtor, on_delete=models.CASCADE, verbose_name='Риэлтор', related_name='realtor')
phone = models.CharField(max_length=20, verbose_name='Телефон')
region = models.CharField(default="Чуйская", max_length=100, verbose_name='Область')
city = models.CharField(default="Бишкек", max_length=100, verbose_name='Город')
district = models.CharField(max_length=100, verbose_name='Район')
title = models.CharField(blank=True, max_length=200, verbose_name='Заголовок')
address = models.CharField(max_length=200, verbose_name='Адрес')
description = models.TextField(blank=True, verbose_name='Описание')
stage = models.IntegerField(verbose_name='Этаж')
rooms = models.IntegerField(verbose_name='Количество комнат')
garage = models.IntegerField(default=0, verbose_name='Гараж')
sqmt = models.IntegerField(verbose_name='Площадь')
price = models.IntegerField(verbose_name='Цена')
photo_main = models.ImageField(blank=True, upload_to='photos/%Y/%m/%d/', verbose_name='Основное фото')
photo_1 = models.ImageField(upload_to='photos/%Y/%m/%d/', blank=True, verbose_name='Фото 1')
photo_2 = models.ImageField(upload_to='photos/%Y/%m/%d/', blank=True, verbose_name='Фото 2')
photo_3 = models.ImageField(upload_to='photos/%Y/%m/%d/', blank=True, verbose_name='Фото 3')
photo_4 = models.ImageField(upload_to='photos/%Y/%m/%d/', blank=True, verbose_name='Фото 4')
photo_5 = models.ImageField(upload_to='photos/%Y/%m/%d/', blank=True, verbose_name='Фото 5')
photo_6 = models.ImageField(upload_to='photos/%Y/%m/%d/', blank=True, verbose_name='Фото 6')
is_published = models.BooleanField(default=True, verbose_name='Публично')
list_date = models.DateTimeField(default=datetime.now, blank=True, verbose_name='Дата публикации')
def __str__(self):
return self.realtor
class Meta:
verbose_name = 'Объявление'
verbose_name_plural = 'Объявления'
class Realtor(models.Model):
name = models.OneToOneField(User, on_delete=models.CASCADE, related_name='realtor', verbose_name='Имя')
photo = models.ImageField(upload_to='photos/%Y/%m/%d/', verbose_name='Фото')
description = models.TextField(blank=True, verbose_name='Описание')
phone = models.CharField(max_length=20, verbose_name='Телефон')
email = models.CharField(max_length=50, verbose_name='Email')
is_mvp = models.BooleanField(default=False, verbose_name='Реэлтор месяца')
hire_date = models.DateTimeField(default=datetime.now, blank=True, verbose_name='Дата приёма на работу')
def __str__(self):
return self.name
class Meta:
verbose_name = 'Риэлтор'
verbose_name_plural = 'Риэлторы'