django动态搜索栏,无需刷新特定字段的页面

时间:2019-07-04 12:24:41

标签: django model field searchbar

我是django的新手,我想使用中心列表中的ajax为每个模型字段应用单独的搜索栏。这意味着我不想刷新页面,也不想在输入搜索框时显示搜索项。请帮帮我!

In models.py file

class Centre(models.Model):
    name= models.CharField(max_length=50, blank=False, unique=True)
    address = models.CharField(max_length =250)
    phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$',
                             message="Phone number must be entered in the format: '+999999999'. Up to 10 digits allowed.")
    contact = models.CharField(max_length=100, blank=False)
    phone = models.CharField(validators=[phone_regex], max_length=10, blank=True)  # validators should be a list
    slug = models.SlugField(unique=False)



In views.py file

@method_decorator(login_required(login_url='/'), name='dispatch')
class centre(CreateView):
    fields = ('name','address','contact','phone',)
    model = Centre
    success_url = reverse_lazy("NewApp:logindex")



def form_valid(self, form):
    form.save()
    return super(centre, self).form_valid(form)

@method_decorator(login_required(login_url='/'), name='dispatch')
class CentreListView(ListView):
    context_object_name = 'centres'
    model = Centre

@method_decorator(login_required(login_url='/'), name='dispatch')
class CentreUpdateView(UpdateView):
     fields = ('address', 'contact', 'phone')  # mention the fields to be updated while updating a school
     model = Centre

0 个答案:

没有答案