I would like to browse related objects in addition to search . like in the raw_id_field widget in the admin.
Is it possible with django-autocomplete-light?
Thanks!
Not with DAL, but you can certainly implement such thing. The article is about populating an HTML select field with a JS popup, but you can just omit that part and populate a text input instead like raw_id_field, all the rest of the article is valid for your case.
Related
In some forms, the search menu stays at the top. I need to see him always. How to do this?
that is Many2many view, the common list doesn't have that kind of structure, if you really need it, you can try to extend the basic search view in the main structure of Odoo.
We use wagtail for our blogs that are part of an eCommerce site. When we want to add a product to the blog as it stands we have to put the exact product name in which then matches on save. As names can change this then breaks that blog which isnt ideal.
What we would like to do is add a field to our streamfield block that lets you pick from our list of products, however as we have 200k+ products and there might be up to 20 products on each blog loading the list into a dropdown is no good. What we need is to replicate what we do in Django admin using django-autocomplete-light where you start typing and get results based on that rather than loading the list into the HTML.
What we cant work out is how to do that within a streamfield block, I have seen libraries like "Wagtail Autocomplete" however it seems you can only use that as a panel rather than within a block. As far as we can see you can only use sub-classes of wagtail.core.blocks or they dont show up in the interface.
Any ideas?
Thanks in advance!
You can extend the editor. Although the examples are mainly focussed on adding CSS style, it still should be possible. You can read more on this at the documentation: http://docs.wagtail.io/en/v2.8/advanced_topics/customisation/extending_draftail.html#
Another option would be is to use the Wagtail autocomplete panel for specifying the product you need to reference to, in a seperate field of course. Then, using a regular f-string replacement, place the proper product details in the text.
Hi guys i have simple Django Form , but I need to get type of this field elements and I made some special operations according to this.
Is there an easy way to get type of Form Field in Django Template?
Any help will be appreciated.
For your actual use case the image widget from the django-form-utils package should be a good match.
On more general level: If you simply want to modify the html generated by a standard widget you should subclass the widget and tweak the render-method.
Take a look at this blog post to get the basic idea.
This is how I would call a individual form field:
{{ form.product }}
This would display only the form element with the name "product". But what about in the case of radio buttons or checkboxes where multiple form fields have the same name. How do I call one over another then?
Is there a way to use value instead of name or some other distinguishing id?
P.S. please don't post any python code suggestions. I am a front end developer and have access to only template tags, filters and variables.
I think you need to work more closely with your Python developers :-)
Basically, if the case were to arise where there are multiple radio buttons/checkboxes with the same name, they should be easily provided to you under the form, using the same schema you're using already.
So, make sure your developer gives you access to all the form elements you need. If they're creating a widget that spits out 4 different radio buttons, you should be able to call them using the way you've done it already, form.some_radio_buttons
Nothing special, just a matter of the backend developer giving you the right information.
I wonder if you could help me.
I have a list of data that will be displayed on one page. There is a simple search box, a list of categories and a list of tags that can all be used to filter the list of data. I'm trying to built it from the ground up (so it doesn't require JavaScript) but eventually it will submit the search criteria and return back a new list using Ajax.
So I have a list of categories in my database ('large', 'small', etc), and I have a list of tags in my database ('wooden', 'brass'). Tags are used to filter down more of what's in the categories. I then have a search box. Ideally, I want the user to effectively tick which categories they want, tick what tags they want and possibly put a search for keywords, and then submit all of that data so it can be queried and a new list of the filtered data can be returned.
I'm not a Django expert, and I'm stuck on how and where to do this... What is the Django way of spitting out the categories as a checkbox list, the tags as a checkbox list and the search box with a submit button... Which when submitted, I can take all that data and do the necessary queries on the database? I don't quite understand how I'd do this... I've been looking at the Django Docs and the Django Book for a few days and the way I'm doing things doesn't seem to be listed.
Please, any help at all would be fantastic.
spitting out the categories as a checkbox list,
the tags as a checkbox list and the
search box with a submit button...
This is a <form> in your HTML page. It probably doesn't match anything in the Django model very well. It's a unique form built more-or-less manually.
I can take all that data and do the necessary queries on the database?
That's a view function.
You'll probably have something like this.
objects= SomeModel.objects
if request.GET ... has categories ...
objects = objects.filter( ... categories ... )
if request.GET ... has tags ...
objects = objects.filter( ... tags ... )
if request.GET ... has search ...
objects = objects.filter( something__contains( search ) )
return render_to_response( ... etc. ... )
the way I'm doing things doesn't seem to be listed.
You're beyond the tutorial here.
What to do?
Do the ENTIRE tutorial. All the way through. Every step. It doesn't seem like it solves your problem, but you MUST do the ENTIRE tutorial.
Design your model. You didn't mention the model in the question. It's the absolutely most important and fundamental thing.
Create the default admin interface for that model. Get the default admin interface to work and do the kinds of things you'd like to do. It has great search, category and tag filtering.
In order to get the default admin to work, you'll need to design fairly sophisticated model and form features. You'll probably have to add method functions to your model as well as choice items and other goodness.
AFTER you have the admin page pretty close to what you want, you can write you own customized view.
each single checkbox has a different name ('category_option_1', 'category_option_2', etc.) ... How do I read these? I can't just put request.POST['category_option_n']?
Really? Why didn't your question say that?
Are you asking about this?
for k in range(1024):
name = 'category_option_{0}'.format(k)
# Use request.POST.get(name,None) to build a `Q` object