django and editable and multiselect choices in ChoiceField - python

I'm trying to get a field of model in Django, which will behave like a ChoiceField but:
will support multiselect
would allow to edit the list of choices
For example - I've got a product, which belongs to several cathegoris: nice, for boys, for men and so on. One product could belong to several categories. Categories can vary across the time.
Currently I'm using MultiSelectField from djang-multiselectfield, which - obviously - handles the first issue.
Is there a ready to use app, which also supports edition of choice list? Or what would be the easiest approach to achieve that?

Related

Alternative Widget for Django Admin Choice Field Select with Many Entries?

I have a model with many country fields and each is a choice field wit list of countries.
The issue is that there's a lot of countries! So each choice field adds a lot of size and rendering time to the page to generate a select dropdown in django admin. (E.g. Making 5 of these read only brought down response time from 10s to 4s!)
I want to see if there's any alternatives known for handling choice field inputs. Since we use ISO-2 for countries, I want to avoid operators having to input values directly as they would not know them.
Ideally I was hoping for some sort of search or select pop-up similar to what happens with raw_id_fields. That way a select list is only generated when needed, but so far havent found
You may try django-jet package or one of its forks. It is fully rewritten django-admin template, and it supports typing search for model choice fields. Or try looking for another package in django packages

Django searchable drop down for ForeignKey widget

in my Django model I have a m2m relation with an intermediate model that contain the two foreign keys of the respective two models.
My problems is that, the first model may have many entries and when I associate it with other model I have a too large drop down widget in the admin.
The default ManyToManyField widget (with filter_horizontal set) may be ok, but it is compatible only with m2m relations....
Is there a solution (even 3rd parts) for the ForeignKeyFields?
Any suggestions?
Edit:
For the other users, I've solved my problem using django-selectable
http://django-selectable.readthedocs.org/en/v0.8.X/index.html
The 3rd party component Django Ajax Selects does exactly what you are looking for.
I played around with django-selectable as well, but found django-autocomplete-light (https://github.com/yourlabs/django-autocomplete-light‎) easier to use and more flexible for what I wanted to achieve.
Perhaps it can be useful to you as well.

Django admin inline popups

Like a many other users here i have been thwarted in trying to get nested inline forms working in the django admin.
I have a data structure that is roughly
Group
- Some data fields
Patrol
- Foreign key to groups
- Some different data fields
Scout
- Foreign key to patrol
- Even more data fields
Ideally when i go to edit a Group record, i would have the admin interface present the Patrol instances linked to scout shown though StackedInline and then have the Scout records related to each of these patrols show up inside an inner TabularInline however this is not currently possible, i have spent a large amount of time trying to port over a patch from two years ago but have had little success.
As far as i see it i have three options open to me
Persist with trying to get this patch from an age ago to work
List patrol objects within a TabularInline without the scout relation and provide an edit patrol members link that pops up a form to edit a patrol in a new window.
Just keep it simple and make users of the system go back and forth between editing group and patrols
Option 2 is what currently looks the most promising but i need advice as to how i could pop up an extra window to edit the patrol in.
Any advice on how to do this, how to get nested inline fields to work or another way in general would be much appreciated.

Limiting options in list filter in Django admin

I'd like to add a "user" column to the list_filters for a Django modeladmin. The model's user column only contains a dozen unique users, however, I have thousands of users, causing the select field to be rendering with thousands of options, making it unusable.
How would I make the select only show the users that are actually used by my model, or at least use some other widget for rendering the select, so the user doesn't have to scroll through thousands of options?
Your question is a little confusing. At first glance, you want to limit what items show up as available filters on the changelist Filters sidebar, but then you go on to talk about selects, which seems to imply you're talking about limiting the options for a field on your change form.
If the latter is the case, #kgr's answer is appropriate, however, if you're asking about the former, see my question and answer regarding a similar thing here on SO

django admin - adding fields on the fly

Basically I am writing a simple shopping cart. Each item can have multiple prices. (i.e. shirts where each size is priced differently). I would like to have a single price field in my admin panel, where when the first price is entered, an additional price field pops up. However I am kind of at a loss as to how to do this. What would be the best way to do this?
Sounds like you want two related models - Item and Option. Item would contain the name of the item, and Option would contain the option - eg size - and the price of that option. You would then set up your admin to use an inline form for Option.
You probably want inlines and some javascript.
You might try checking out the Satchmo codebase. It has something similar that may provide some inspiration. http://satchmoproject.com

Categories

Resources