allow fts search on foreign key / fix DocumentSubject search
This commit is contained in:
parent
4ee0e66859
commit
53d93b318c
|
@ -205,7 +205,7 @@ class ItfModel(models.Model):
|
||||||
qstring = f + '__icontains'
|
qstring = f + '__icontains'
|
||||||
qobject = Q(**{qstring:t})
|
qobject = Q(**{qstring:t})
|
||||||
qobjects.append(qobject)
|
qobjects.append(qobject)
|
||||||
return qset.filter(reduce(operator.or_, qobjects))
|
return qset.filter(reduce(operator.or_, qobjects)).distinct()
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -266,6 +266,7 @@ class DocumentSubject(ItfModel):
|
||||||
title = models.CharField(max_length=255)
|
title = models.CharField(max_length=255)
|
||||||
main_image = models.ImageField(upload_to='upload/images/festival/main/', blank=True, null=True)
|
main_image = models.ImageField(upload_to='upload/images/festival/main/', blank=True, null=True)
|
||||||
|
|
||||||
|
fts_fields = ['title', 'document__title', 'document__intro']
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ import floppyforms as forms
|
||||||
from registration.forms import RegistrationForm
|
from registration.forms import RegistrationForm
|
||||||
from models import *
|
from models import *
|
||||||
from registration.models import RegistrationProfile
|
from registration.models import RegistrationProfile
|
||||||
|
import json
|
||||||
|
|
||||||
class ItfRegistrationForm(RegistrationForm):
|
class ItfRegistrationForm(RegistrationForm):
|
||||||
subscribe = forms.BooleanField(help_text='Subscribe to newsletter?')
|
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
|
#Actual person form definition
|
||||||
class PersonForm(forms.ModelForm):
|
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())
|
# occupations = forms.ModelMultipleChoiceField(Occupation.objects.all(), widget=forms.CheckboxSelectMultiple())
|
||||||
email = forms.EmailField(widget=forms.EmailInput(attrs={'placeholder': 'john@example.com'}))
|
email = forms.EmailField(widget=forms.EmailInput(attrs={'placeholder': 'john@example.com'}))
|
||||||
|
|
||||||
# inlines = [ConnectionFormset, ProductionFormset]
|
# inlines = [ConnectionFormset, ProductionFormset]
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Person
|
model = Person
|
||||||
|
@ -27,6 +49,6 @@ class PersonForm(forms.ModelForm):
|
||||||
'last_name': forms.TextInput,
|
'last_name': forms.TextInput,
|
||||||
'occupations': forms.CheckboxSelectMultiple
|
'occupations': forms.CheckboxSelectMultiple
|
||||||
}
|
}
|
||||||
exclude = ('connections', 'productions')
|
#exclude = ('connections', 'productions')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,9 @@ from ox.django.shortcuts import render_to_json_response
|
||||||
from django.core.paginator import Paginator, InvalidPage, EmptyPage
|
from django.core.paginator import Paginator, InvalidPage, EmptyPage
|
||||||
|
|
||||||
def person_form(request):
|
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):
|
def autocomplete(request):
|
||||||
|
|
|
@ -108,9 +108,7 @@ $(function(){
|
||||||
})();
|
})();
|
||||||
|
|
||||||
if (deletedItem) {
|
if (deletedItem) {
|
||||||
if (!confirm("are you sure you wish to delete?")) {
|
|
||||||
$this.select2("val",
|
|
||||||
}
|
|
||||||
console.log("deleted", deletedItem);
|
console.log("deleted", deletedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +147,7 @@ $(function(){
|
||||||
<div id="searchContainer">
|
<div id="searchContainer">
|
||||||
<form id="formItf" action="" class="uniForm" method="POST">
|
<form id="formItf" action="" class="uniForm" method="POST">
|
||||||
<div>
|
<div>
|
||||||
<input type="hidden" data-placeholder="Choose Connections" id="id_connections" name="connections" style="width:600px" />
|
<!-- <input type="hidden" data-placeholder="Choose Connections" id="id_connections" name="connections" style="width:600px" /> -->
|
||||||
</div>
|
</div>
|
||||||
{{ form|crispy }}
|
{{ form|crispy }}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user