i have some trouble about influxdb+django configurations.
Firstly let me summarize my situation. I have an influxdb which is already collecting data from endnode(sensors). Data is transfering by LoraWan technology. I can read that datas from terminal by writing flux queries so database is working without any problem.
Now my second phase of this project is visualizing that datas on an web page. I am using django framework for that i completed the frontend parts nearly. I looked on internet for the configurations for influxdb on django but i couldnt handle it. In django documentation page they are listed some databases like below:
Django officially supports the following databases:
PostgreSQL
MariaDB
MySQL
Oracle
SQLite
How will i use/configure and get data from my influxdb ? Is it possible ? What are the alternative solutions.
Sure, Django doesn't support InfluxDB for its usual models (authentication and what-have-you, and of course your own apps), but you can simply use the InfluxDB Python client library to make a query in a view and e.g. return JSON data.
Adapting from the readme, you might have a view like
from influxdb_client import InfluxDBClient
client = InfluxDBClient(url="http://localhost:8086", token="my-token", org="my-org")
def get_data(request):
bucket = "my-bucket"
query_api = client.query_api()
result = query_api.query_csv('from(bucket:"my-bucket") |> range(start: -10m)')
return JSONResponse(result)
Related
i followed this solution to run customer django command programmatically , but it is limited for just one database connection.
I have django app configured with multiple database , is it possible to run custom django command using specific database connection?
exactly like when we use connections["DB_NAME_CONNECTION"].cursor() to execute an sql query
thanks a lot for your help!
One option is to create a new settings module (here's a guide) that contains your specific database connection configuration, and then use that settings module when using call_command():
management.call_command('mycommand', '--settings=mysite.settings.specificconnection')
I built a small django app and created some models. Now I would like to populate the database (the tables and rows do already exist) using a python script since I have to read the information I want to populate the database with, from multiple external files. Is there any way to do that?
EDIT:
Python 3.7
Django 3.0
You can always use any python routine to read files, process the content, create your model instances and save them the to the database by using a custom Django management command.
check this out: how to import csv data into django models
In one of my project, I'm using mongoengine 0.9 and pymongo 2.8 for the database and python django as a framework. I came through the view concept in mongodb and created a view in the database for a model named User. But I don't know how to access the view from mongodb using pymongo. Anyone have any suggestion, please help?
The error message I'm getting while trying to iterate over the cursor is:
database error: Namespace db.collection is a view. OP_GET_MORE operations are not supported on views. Only clients which support the getMore command can be used to query views.
MongoDB have feature called op codes in your case that is OP_GET_MORE to communicate with the db. Overtime some of these have been replaced and in your case client is not supporting getMore command. Please check your version.
I set up a simple django site using django-allauth.
I created some oauth providers in the database.
Everything is fine and working on my laptop now.
I would like to store the created database tables somehow.
Use case: I want to set up a new development environments on a different PC painlessly.
How to store the initial data of django_allauth, so that after checking out the app from git the command manage.py migrate is all I need to have the relevant database tables filled?
Django_allauth already save those data to the database, you will find them in a table *_SocialApp, here is the model code from django_auth source
What would be the best way to port an existing Drupal site to a Django application?
I have around 500 pages (mostly books module) and around 50 blog posts. I'm not using any 3rd party modules.
I would like to keep the current URLS (for SEO purposes) and migrate database to Django. I will create a simple blog application, so migrating blog posts should be ok. What would be the best way to serve 500+ pages with Django? I would like to use Admin to edit/add new pages.
All Django development is similar, and yours will fit the pattern.
Define the Django model for your books and blog posts.
Unit test that model using Django's built-in testing capabilities.
Write some small utilities to load your legacy data into Django. At this point, you'll realize that your Django model isn't perfect. Good. Fix it. Fix the tests. Redo the loads.
Configure the default admin interface to your model. At this point, you'll spend time tweaking the admin interface. You'll realize your data model is wrong. Which is a good thing. Fix your model. Fix your tests. Fix your loads.
Now that your data is correct, you can create templates from your legacy pages.
Create URL mappings and view functions to populate the templates from the data model.
Take the time to get the data model right. It really matters, because everything else is very simple if your data model is solid.
It may be possible to write Django models which work with the legacy database (I've done this in the past; see docs on manage.py inspectdb).
However, I'd follow advice above and design a clean database using Django conventions, and then migrate the data over. I usually write migration scripts which write to the new database through Django and read the old one using the raw Python DB APIs (while it is possible to tie Django to multiple databases simultaneously, too).
I also suggest taking a look at the available blogging apps for Django. If the one included in Pinax suits your need, go ahead and use Pinax as a starting point.
S.Lott answer is still valid after years, I try to complete the analysis with the tools and format to do the job.
There are many Drupal export tools out of there by now but with the very same request I go for Views Datasource choosing JSON as format. This module is very solid and available for the last version of Drupal. The JSON format is very fast in both parsing and encoding and it's easy to read and very Python-friendly (import json).
Using Views Datasource you can create a node view sorted by node id (nid), show a limited number of elements per page, configure a view path, add to it a filter identifier and pass to it the nid to read all elements until you get an empty JSON response.
When importing in Django you have a wide set of tools as well, starting from loaddata to load fixtures. Views Datasource exported JSON but it's not formatted as Django expects fixtures: you can write a custom admin command to do the import, where you can have the full control of the import flow.
You can start your command passing a nid=0 as argument and then let the procedure read, import and then fetch data from the next page passing simply the last nid read in the previous HTTP request. You can even restrict access to the path on view but you need additional configuration on the import side.
Regarding performance, just for example I parsed and imported 15.000+ nodes in less than 10 minutes via a Django 1.8 custom admin command on an 8 core / 8 GB Linux virtual machine and PostgreSQL as DBMS, logging success and error information into a custom model for each node.
These are the basics for import/export between these two platform, for detailed information I described all the major steps for export from Drupal and then import to Django in this guide.