1

I'm having trouble to make an field already filled working as query on form. I'm using ajax-select to render the fields.

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)

So I'm trying to figure out, what are the good practices to make this work.

I need to fill first the quarter, so the typePlace. To reach the correct Places, to reach the correct attributes to fill the correct items.

cleliodpaula
  • 819
  • 2
  • 11
  • 27
  • 1
    I'm afraid django-ajax-selects does [not support this feature out of the box](http://www.djangopackages.com/grids/g/auto-complete/). However, it is easy with [django-selectable](http://django-selectable.readthedocs.org/en/version-0.5.2/advanced.html#chained-selection) and [django-autocomplete-light](http://django-autocomplete-light.readthedocs.org/en/latest/dependant.html). – jpic Aug 24 '12 at 05:26

0 Answers0