How to FilteringSelect.

6 views
Skip to first unread message

Enrique San Martín W.

unread,
Feb 23, 2010, 12:12:14 PM2/23/10
to dojango-users
Hello, i'm trying to implement the widget FilteringSelect in my
project, but i can't find how to create a ModelStore to make the
filter.

The models.py it's like this:

class OrdenDeCompra(models.Model):
proveedor = models.ForeignKey(Ficha)


and i have some like this in my forms.py:

class OrdenDeCompraForm(forms.ModelForm):
proveedor = forms.ModelChoiceField(Ficha.objects.all(),

widget=forms.FilteringSelect())


any sugestion? regards :)

klipstein

unread,
Feb 24, 2010, 5:39:21 PM2/24/10
to dojango-users
Hi Enrique,

you first have to create a new file where you define your model-
stores, e.g. 'stores.py' in Django's project folder:

from myapp.models import OrdenDeCompra
from dojango.data.modelstore import *

class OrdenDeCompraStore(Store):
proveedor = StoreField()

class Meta(object):
objects = OrdenDeCompra.objects.all()
label = 'proveedor'

Now you can easily query your store within a Django view like this
('myapp/views.py'):

from stores import OrdenDeCompraStore
def compra_store(request):
store = OrdenDeCompraStore()
return HttpResponse( '{}&&\n' + store.to_json(),
mimetype='application/json' )

And of course this has to be wired up within your 'urls.py':
urlpatterns = patterns('',
url(r'^compra-store/$', 'myapp.views.compra_store', name='compra-
store'),
...
)

Pointing your browser to http://localhost:8000/compra-store now serves
a FilteringSelect-compatible JSON-file that can be wired with a
FilteringSelect within your form.

class OrdenDeCompraForm(forms.ModelForm):
provedoor = FilteringSelectStore("/compra-store")

Don't know if this FilteringSelectStore ist available within dojango
0.4.6 already, so i would recommend that you should use the version
from SVN. FilteringSelectStore is using the
dojo.data.ItemFileReadStore as default, where no server-side querying/
paging is done.

Greetings, Tobias

klipstein

unread,
Feb 24, 2010, 5:43:52 PM2/24/10
to dojango-users
Just see, that you have to query the model 'Ficha' instead of
'OrdenDeCompra'.

On Feb 24, 11:39 pm, klipstein <tobias.klipst...@googlemail.com>
wrote:


> Hi Enrique,
>
> you first have to create a new file where you define your model-
> stores, e.g. 'stores.py' in Django's project folder:
>
> from myapp.models import OrdenDeCompra
> from dojango.data.modelstore import *
>
> class OrdenDeCompraStore(Store):
>     proveedor = StoreField()
>
>     class Meta(object):
>         objects = OrdenDeCompra.objects.all()
>         label = 'proveedor'
>
> Now you can easily query your store within a Django view like this
> ('myapp/views.py'):
>
> from stores import OrdenDeCompraStore
> def compra_store(request):
>     store = OrdenDeCompraStore()
>     return HttpResponse( '{}&&\n' + store.to_json(),
> mimetype='application/json' )
>
> And of course this has to be wired up within your 'urls.py':
> urlpatterns = patterns('',
>     url(r'^compra-store/$', 'myapp.views.compra_store', name='compra-
> store'),
>     ...
> )
>

> Pointing your browser tohttp://localhost:8000/compra-storenow serves

Reply all
Reply to author
Forward
0 new messages