From 53d93b318c91f8a36f04a784b172c6771a98560c Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 24 Jun 2012 17:15:44 +0530 Subject: [PATCH] allow fts search on foreign key / fix DocumentSubject search --- itf/app/models.py | 2 +- itf/festival/models.py | 1 + itf/itfprofiles/forms.py | 26 ++++++++++++++++++++++++-- itf/itfprofiles/views.py | 4 +++- itf/templates/test/person_form.html | 6 ++---- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index 65e3a1e..02cfa01 100755 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -205,7 +205,7 @@ class ItfModel(models.Model): qstring = f + '__icontains' qobject = Q(**{qstring:t}) qobjects.append(qobject) - return qset.filter(reduce(operator.or_, qobjects)) + return qset.filter(reduce(operator.or_, qobjects)).distinct() ''' diff --git a/itf/festival/models.py b/itf/festival/models.py index d4bac8f..b79c196 100755 --- a/itf/festival/models.py +++ b/itf/festival/models.py @@ -266,6 +266,7 @@ class DocumentSubject(ItfModel): title = models.CharField(max_length=255) main_image = models.ImageField(upload_to='upload/images/festival/main/', blank=True, null=True) + fts_fields = ['title', 'document__title', 'document__intro'] def __unicode__(self): return self.title diff --git a/itf/itfprofiles/forms.py b/itf/itfprofiles/forms.py index 5f16f38..86650c6 100644 --- a/itf/itfprofiles/forms.py +++ b/itf/itfprofiles/forms.py @@ -2,6 +2,7 @@ import floppyforms as forms from registration.forms import RegistrationForm from models import * from registration.models import RegistrationProfile +import json class ItfRegistrationForm(RegistrationForm): subscribe = forms.BooleanField(help_text='Subscribe to newsletter?') @@ -14,11 +15,32 @@ class ItfRegistrationForm(RegistrationForm): +class ConnectionsWidget(forms.SelectMultiple): + template_name = 'formwidgets/select2_multiple.html' + + ''' + def get_context_data(self): + ctx = super(ConnectionsWidget, self).get_context_data() + + #ctx['data_json'] = [{'id': obj[0], 'text': obj[1]} for obj in self.choices] + return ctx + ''' + + def get_context(self, name, value, attrs, *args, **kwargs): + import pdb + pdb.set_trace() + ctx = super(ConnectionsWidget, self).get_context(name, value, attrs) + ctx['data_json'] = "hi" # json.dumps(choices) + return ctx + + #Actual person form definition class PersonForm(forms.ModelForm): +# occupations = forms.ModelMultipleChoiceField(Occupation.objects.all(), widget=forms.CheckboxSelectMultiple()) + connections = forms.ModelMultipleChoiceField(Person.objects.all(), widget=ConnectionsWidget()) # occupations = forms.ModelMultipleChoiceField(Occupation.objects.all(), widget=forms.CheckboxSelectMultiple()) email = forms.EmailField(widget=forms.EmailInput(attrs={'placeholder': 'john@example.com'})) - + # inlines = [ConnectionFormset, ProductionFormset] class Meta: model = Person @@ -27,6 +49,6 @@ class PersonForm(forms.ModelForm): 'last_name': forms.TextInput, 'occupations': forms.CheckboxSelectMultiple } - exclude = ('connections', 'productions') + #exclude = ('connections', 'productions') diff --git a/itf/itfprofiles/views.py b/itf/itfprofiles/views.py index 257570e..eccabaf 100644 --- a/itf/itfprofiles/views.py +++ b/itf/itfprofiles/views.py @@ -6,7 +6,9 @@ from ox.django.shortcuts import render_to_json_response from django.core.paginator import Paginator, InvalidPage, EmptyPage def person_form(request): - return render_to_response("test/person_form.html", {'form': PersonForm}) + person = Person.objects.all()[0] + form = PersonForm(instance=person) + return render_to_response("test/person_form.html", {'form': form}) def autocomplete(request): diff --git a/itf/templates/test/person_form.html b/itf/templates/test/person_form.html index 0afc9fe..48cc635 100644 --- a/itf/templates/test/person_form.html +++ b/itf/templates/test/person_form.html @@ -108,9 +108,7 @@ $(function(){ })(); if (deletedItem) { - if (!confirm("are you sure you wish to delete?")) { - $this.select2("val", - } + console.log("deleted", deletedItem); } @@ -149,7 +147,7 @@ $(function(){
- +
{{ form|crispy }}