Comments (7)
I was wondering if there's any update on this feature?
I'm currently working on something like this, and was curious of the best
approach.
One can just check if the ajax results come back empty AND user enters some
text, then
just create the new foreign field automatically.
Original comment by [email protected]
on 3 Mar 2010 at 6:46
from django-ajax-selects.
I just added support for adding via a pop up. (green +)
@yevmail You can do what you want to do by using an AutoComplete. have the
channel search for models and
return the name of the object. in your form implement clean_fieldname() and at
that point lookup the model by
name using YourModel.objects.get_or_create(name=name) and insert it into
cleaned_data[fieldname]. I think that
should work
Original comment by [email protected]
on 6 Mar 2010 at 12:02
from django-ajax-selects.
[deleted comment]
from django-ajax-selects.
Has anyone got this working?
I had to modify the clean() method on the form field, but that method gets the
foreignkey (pk-value) passed after validation and will not receive the actual
text input (name). If the input does not match an existign FK object, the value
passed to clean() will be empty and there is no request object to grab the text
input from, so no way to Model.objects.get_or_create.
I would really like to see this feature implemented.
Original comment by [email protected]
on 22 Sep 2010 at 4:06
from django-ajax-selects.
Hi, I need to resurrect this. crucialfelix, can you please show how to do it?
I'd like to look at some code I can then integrate with mine. Thanks!
Original comment by [email protected]
on 7 Dec 2010 at 3:30
from django-ajax-selects.
Some code to look at would help a lot. But since last activity was a year ago,
maybe Felix won't make it available.
Original comment by [email protected]
on 6 Dec 2011 at 7:07
from django-ajax-selects.
The code has moved to https://github.com/crucialfelix/django-ajax-selects
as for this feature, to be honest I am driven by my own client's needs and I
haven't needed this.
just off the top of my head thinking about it : use an AutoComplete field (not
a foreign key one) and give it a unique field name that is not on the model.
implement Form save() and you should have access to the
cleaned_data['fake_field'] and can get_or_create there and set the fk on the
instance.
Original comment by [email protected]
on 6 Dec 2011 at 8:30
from django-ajax-selects.
Related Issues (20)
- Selected fields not saved on form submission from the frontend (admin works fine) HOT 14
- Unclear documentation for Add Object popup and link HOT 2
- Channel customisation to hide input on select HOT 1
- Unable to use values() in get_query method HOT 6
- JavaScript needs to be quoted HOT 7
- Initial value causes error. HOT 2
- Empty help string will display gettext header HOT 5
- Caught ValueError while rendering: invalid literal for int() with base 10: HOT 2
- Retain text in the input box HOT 5
- Show form field without a fk HOT 3
- Trigger only after 'n' characters HOT 1
- The ajax_lookup view should return a 'text/plain' Content-Type HOT 3
- Invalid markup HOT 3
- Doc suggestion: add a class Meta on ContactMailingForm HOT 1
- [patch] Field with name 'media' clashes with ModelForm.media
- JS incorrectly calculating the locations.. HOT 2
- Incorrect location of static files HOT 5
- make_ajax_field method overlooks initial value HOT 2
- {{ field.contents }}should render the display version of a field HOT 1
- tag the git source code HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-ajax-selects.