我无法将已填充的字段用作表单上的查询。 我正在使用ajax-select来渲染字段。
forms.py
class FormMakeOccurrence(forms.ModelForm):
class Meta:
model = ManageOccurrence
fields = ('attribute', 'item', 'place')
place = make_ajax_field(ManageOccurrence,'place','places', help_text=None)
typeplace = make_ajax_field(TypePlace,'name','tipos_lugares', help_text=None)
quarter = make_ajax_field(Quarter,'name','blocos', help_text=None)
lookup.py
class PlaceLookup(LookupChannel):
model = Place
def get_query(self,q,request):
return Place.objects.filter(Q(name__icontains=q) | Q(typePlace__name__exact="AN FILLED FIELD") | Q(quarter__name__exact="AN FILLED FIELD"))
class TypePlaceLookup(LookupChannel):
model = TypePlace
def get_query(self,q,request):
return TypePlace.objects.filter(Q(name__icontains=q)).order_by('name')
models.py
class ManageOccurrence(models.Model):
attribute = models.ForeignKey(Attribute)
item = models.ForeignKey(TypeItem)
place = models.ForeignKey(Place)
... other fields
class Place(models.Model):
name = models.CharField(max_length=30)
typePlace = models.ForeignKey(TypePlace)
quarter = models.ForeignKey(Quarter)
所以我想弄清楚,做这项工作的好方法是什么。
我需要先填写季度,所以typePlace。要到达正确的位置,要获得正确的属性以填充正确的项目。