I'm working on a small project using Django and I have a detail page of a digital product. The user should have the avability to update the status of this product through 3 Buttons. This status represents one ChoiceField in the database. The choices are: Dismiss, In Review and Approve.
Clicking the button should submit the form directly.
My question is, what is the best way to solve that (without Ajax)?
My first idea was to add 3 forms and every form has another action url.
I'm still fairly new to Django and don't know if my approach is the best solution.
As described in this question and in the docs you should be able to get what you want with a RadioSelect form widget.
If you add a bit of CSS to hide the radio inputs themselves, and style the labels as buttons, you should be good!
Edit to include my comment below:
To get a single click submission, you could write some simple javascript that catches the onclick event on your buttons, and submits the form as you click.
Related
I am making a website running wagtail as the CMS/backend and use Page for things that are actual web pages on the site. In addition to this I will need an Events section and I am unsure whether to make it as a Wagtail Page or Django models.Model.
The way I would like this to work for the user is to have an Events section in the admin panel using ModelAdmin so that the user can easily find and navigate to all Events, and, for those events to be displayed in various sections of the site - Home Page, Events Page, Article Page for example.
I think using Page for this and requiring the user to navigate to it (Home > Events Listing > Event Detail) each time is rather a waste of time and cumbersome as opposed to having it use ModelAdmin paired with Django models.Model and that being 1 or 2 clicks away.
Reading through my question it's obvious I am leaning towards using Django model for this, so my question is: what is the trade-off between the two? Is there a set use case for using one or the other? Would using one mean having more/less functionality over the other and what would those be?
Note: I know my question is almost identical to Guidelines for using Wagtail Pages or Django models? however it's more focused on ecommerce but most importantly it has no answer.
Use models.Model and register as a snippet because it will give you more flexibility.
As a user mentioned above, using a snippet is a great idea for what you're discussing. It's one click on the admin and they're in the event system. Then, you can just pass that model into the context for a page. Here's an example of doing this in Wagtail. See this example on adding snippets as streamfield if you wanted the customer to be able to place the events manually through the CMS.
Bear with my in this moment of confusion.
I have a project for a small clinic, which will be made using Python+Django.
It's a "very simple" application: they want their patients list and their consults list.
I will do this in Django, using only the admin interface(because it's the only way I know). It will be separated in two modules, one for patients, other for consults.
Here is my question: When the user adds a new consult on the django admin interface, is it possible for him to double click the name of that patient in the form input to open a window with the patient page? (the django admin patient module page)
Look at the screen-shot above, it's a selector with the lists of all patients(this is one of the inputs when inserting a new consult), the NORMAL BEHAVIOR of this is when you click someone, it highlights, when its highlighted and you click the arrow, it passes to the other site, or when you DOUBLE CLICK someone, it passes to the other side too.
What I wanted to do, is when you double click someone, it opened the patient window. Is this possible?
Thanks in advance.
I'm a new on Django. One question confused me about the drop down list in Django. I'd like to know how to change the content in a page based on the selection in the drop down list in Django.
In Model.py I design the fields as:
STATUS_IN_CHOICE = (
('Pending','Pending'),
('Passed','Passed'),
('Failed','Failed'),
)
Status = models.CharField(max_length=10,choices=STATUS_IN_CHOICE,
default='Pending')
The respected result I want is, if I select "Passed" in the drop down list. All the passed cases show in the page. Others are the same.
I have no idea how to code the template and connect with the field now. Cause in my opinion, it's not a forms (post) at all.
You have basically two alternatives, and both of involve the use of javascript.
You either:
need to preload all content at the initial page render, if the content is small and simple, and then use javascript on the drop-down to display the appropriate parts of it.
or to fetch the content with ajax requests depending on the value of the drop-down and render it when it loads.
Neither of the above the use of a model if the drop-down is for display filter only, and no storing is required. You could achieve the same with a simple django form or plain HTML.
Is there a widget for rendering a foreign key field in Django admin that can scale to handle an arbitrarily large table and provide a user-friendly interface for looking up a FK?
The default widget in Django 1.3 is a select box that lists every record in the referenced table. For tables containing hundreds of thousands of records...this basically crashes the server. I see there's a ref_id_fields ModelAdmin option, for rendering the field as a simple text box, but that strikes me as a pretty un-user-friendly workaround since it expects the user to know the exact ID for the record they want to reference.
I'm surprised no solution for this is already builtin, but Googling only found me one project implementing a jQuery-powered autocomplete widget. Are there any other solutions for this problem?
are you getting all the static files? raw_id_fields come with an ajax widget, which puts a little magnifying glass next to the text box with the input widget. clicking brings up a popup with a changelist (including e.g. search) that you can use to find the id. (and automatically insert by clicking the entry)
see screenshot (first google image search)
There are several more auto-complete apps for Django: http://djangopackages.com/grids/g/auto-complete/
I've got a web page I'm generating with Pylons and the evoque templating tool. I'm trying to generate a page with multiple forms per page (one form is part of a base template that becomes part of every page). I'm having a problem as I seemingly can only get the form element values for one form; whenever I try to get the value from the base template, I get nothing back. Is there a way in Pylons to get a form element from a form by name? I'm using the request.params("variable_name") style that is standard in Pylons.
Thanks in advance for your help!
Doug
You will only get the form values for the form that was posted in the request(ie: whichever submit button the user clicked), that's how html works.
Yes (to iterate Tom's answer), HTML is designed to explicitly only allow a single form to be submitted at a time. Plus, forms may not be nested, so no confusion possible there.
However, a single form may contain multiple submit buttons. So, you may if you really want to organize your page as one big single form, and so submitting will submit all the values each time. You will need to take care then that there are all field names are distinct -- so, not convenient if you have a repetition of "item" forms, in which case it should be a lot cleaner to have a form per item...