is there a good package to parse XML/JSON data and map it to Django model's object fields? The ideal solution would be the one that supports object updates. What can you recommend?
UPDATE:
Will tell a bit about my requirements. There affiliate programs that supply partners with content via XML feeds. What I need is to parse the feed time from time and get content out of it and update already existing content (objects).
Related
I have a similar situation as this post in which I encounter a slow page loading as I have thousands of entries in a foreignkey field.
At modelform, is there a way to improve the page loading while keeping the dropdown function? I have used select2 to efficiently find the chosen item in the dropdown, thus want to keep this function.
Django has to fetch all those foreignkey objects from database and then render them as HTML. This is why it takes a lot of time. Fetching from database can be pretty quick if you cache everything, but rendering to HTML will still be a problem.
Here's a solution that I think would work best:
Exclude that ForeignKey field from your form.
Instead, just create a blank input field. You'll have to capture user's input via JavaScript and send that value to your backed to fetch suggestions. In fact, select2 supports fetching data from backend via AJAX, So, half of your work is done.
Create a view which will take that AJAX request and search the database for suggestions and send them back to the client.
And you're done.
Does anybody know how can I make real-time highlighting in forms in Django?
Here's what I'm doing: I have a model, and a few instances of it. I'm serializing the selected object to json and sending it to my form (e.g. textarea). Then I can edit it, deserialize, and send it back to the db. Are there any options for highligting this json text in real time?
It doesn't seem as if django-postman supports attachments so I'm trying to add attachment support. I'm thinking of doing it by creating another set of models that will refer to a postman message and then update the views/templates accordingly but it will be a fair amount of work.
Django-postman isn't exactly an SMTP based messaging system so attachments would need to implemented through a different module. I think you should check some of the django file management projects
https://www.djangopackages.com/grids/g/file-managers/
One of the simplest idea I can think of is to save files in some kind of hashed name and associate these names with the postman message .
I think this would be a good addition to postman itself.
So I ended up figuring out how to do this on my own but it could use some work. The additional constraint we had to work with was that we were already using jQuery File Upload to upload files via AJAX so we needed a way to integrate the two.
Our solution was to create an app that contained a new model and a custom reply form that made it relatively easy to link the two together.
I wrote it up at http://dangoldin.com/2013/05/17/adding-attachments-to-django-postman/ and hope it helps others.
I noticed recently that ELMAH has support for exporting details of an exception via JSON and XML. Out of sheer curiosity, why would anyone use this?
If I was storing my data in a SQL DB, why not retrieve the value from there? Additionally, the errors are stored in a pseudo xml format already... why export something that's already in xml to xml?
Just wondering...
The JSON and XML export features were added to enable and encourage anyone to develop a client to ELMAH using simply HTTP for access rather than relying on the choice of back-end storage. A client can be, for example, written to provide alternative and richer views (dashboards or using Ajax) in addition to the built-in ones, perform analytics, full-text search and more.
A basic client would need to take one or more “home” URLs of ELMAH deployments and build a TOC of the log. This is easily done by simply downloading the CSV off the home URL. Each record in the CSV provides a URL to the detailed entry, which in turn can be used to get the full details of an error in XML or JSON.
Plone has a beautiful search box with a "Google suggest" like functionality for its site. It even indexes uploaded documents like PDFs. Does anyone know of a module that can provide this kind of functionality in a Django site?
Plone implements it's LiveSearch feature by maintaining a separate metadata table of indexed attributes (fields such as last modified, creator, title are copied from the content objects into this table). Content objects then send ObjectAdded/ObjectModified/ObjectRemoved events, and an event subscriber listens for these events and is responsible for updating the metadata table (in Django events are named signals). Then there is a Browser View exposed at a fixed URL that searches the metadata and returns the appropriate LiveSearch HTML, and finally each HTML page is sent the appropriate JavaScript to handle the autocomplete AJAX functionality to query this view and slot the resulting HTML results into the DOM.
If you want your LiveSearch to query multiple Models/Content Types, you are likely going to need to send your own events and have a subscriber handle them appropriately. This isn't necessary for a smaller data sets or lower traffic sites, where the performance penalty for doing multiple queries for a single search isn't a concern (or you only want to search a single content type) and you can just do several queries from your View.
As for the JavaScript side, you can roll-your-own or use an existing JavaScript library. This is usually called autocomplete in the JS library. There is YUI autocomplete and Scriptaculous autocomplete for starters, and likely lots more JavaScript autocomplete implementations out there. Plone uses KSS for it's JavaScript library, the KSS livesearch plugin is a good place to start if looking for example code to pluck from.
http://pypi.python.org/pypi/kss.plugin.livesearch
And a tutorial on using KSS with Django:
http://kssproject.org/docs/tutorial/kss-in-django-with-kss-django-application
KSS is quite nice since it cleanly separates behaviour from content on the client side (without needing to write JavaScript), but Scriptaculous is conceptually a little simpler and has somewhat better documentation (http://github.com/madrobby/scriptaculous/wikis/ajax-autocompleter).