How to use Arangodb in Django database? - python

I am starting developing a website, I want to use Django and Arangodb, but Django's built-in databases backend does not support arango.
django documentation refers to this in database section:
You can use a database backend that doesn’t ship with Django by setting ENGINE to a fully-qualified path (i.e. mypackage.backends.whatever).
but I could not find anything that bridges between Django and Arango. there is this repo in GitHub https://github.com/pablotcarreira/django-arangodb but this does not support new features of Django and Arango.
I would like any thread to lead me to solve this problem.

Navigate this projects:
https://github.com/pablotcarreira/django-arangodb
Build API for Django with Foxx or use ArangoDB Python driver?

You must first create an app for the database, for example dbms, and then implement all the required items such as crud in a .py file yourself and use the query class in the view you want and return it such as list ,dict or ... .
Note ! In the __init __ file, be sure to create an object from the created class

Related

Can I use an external database table for the login process in Django?

So I'm starting a new Django project that essentially requires the login & registration process be routed through an EXTERNAL & ALREADY created database.
Is it possible to have the User model use an EXTERNAL database table ONLY when Django is:
Logging in a user, to check if the login is valid
Registering a user, inserting data for that user in the external database
I would like for the rest of the Django server to use a local database.
If so, could someone either provide examples or guide me to documentation on the subject?
Easiest way to use multiple database with Django is to use a database routing. By default Django stick to single database, however, if you want to implement more interesting database routing system, you can define and install your own database routers.
Database routers are installed using the DATABASE_ROUTERS setting. You have to specify this setting in your settings.py file
What you have to do is write one AuthRouter as described Django documentation Django Multiple Database
"Yes, but"
What you are looking for in the docs is called "database router".
There is even an example for the auth app in the docs there.
But, there is s serious drawback to consider with this approach:
We cannot have cross-database relationships in the models. If auth tables are in a separate database, this means that any otehr app that needs a foreign key to User model is going to run into problems. You might be able to "fake" the relationships using a db that doesn't enforce relationship checks (SQLite or MyISAM/MySQL).
Out of the box, such apps are: session, authtoken, and admin (and probably more).
Alternatively, a single-sign-on solution might do a better job: django-sso, or django-mama-cas + django-cas-ng, or the commercial Stormpath.

Django Rest Framework Token Authentication with MongoEngine User

I am using a Django installation with MongoEngine to get MongoDB to work as my project's backend.
I've got the implementation to work but am stuck with Django Rest Framework's authentication system. Was just reading the API guide for their authentication chapter and was trying out their TokenAuthentication.
Tokens are created using
t = Token.objects.create(user=..)
and it expects a Django User instance. Since I am using MongoEngine, my database entry in the settings.py file is set to Dummy.
So how do I create a user instance that can be used by Token class.
I tried creating users using MongoEngine's mongoengine.django.auth but the Token class isn't accepting this object.
The resulting error is:
ValueError: Cannot assign "<User: gaurav>": "Token.user" must be a "User" instance.
Please let me know how I can get this to work.
Unfortunately you have to write it for yourself. As a reference you can use a gist I just created: https://gist.github.com/RockingRolli/79ceab04adb72c106cd6
I solved the issue a few weeks ago and it works. The code basically is inheriting the TokenAuthentication and adds Mongoengine specific behaviour.
There are also Django user features provided by Mongoengine: http://docs.mongoengine.org/en/latest/django.html#custom-user-model - IIRC you also need them for MongoTokenAuthentication.
All in all using Django (+Rest Framework) with Mongoengine can be tricky at some point and currently it looks like these issues will not be resolved soon.

Where to instantiate shared thread objects in Django, equiv of pyramid registry?

I'm plugging some framework agnostic code of mine into Django instead of Pyramid. It uses SQLAlchemy and has a customized session factory object for getting db sessions. In pyramid, I instantiate this at server start up in the main app method and attach it to the registry so that all other parts of my app can get at it. I'd like to know what the "correct" way of instantiating and making available a shared factory is in Django. Is there somewhere canonical for putting something like that so that Django users will find it easily and the code will be readable to people used to Django patterns?
thanks
I place my SQLAlchemy/SQLSoup connections at models.py, because it is related to persistence (and to the "model" layer of Model-View-Whatever).
You can even replace the Django ORM with SQLAlchemy if you are not using applications relying on the first like django.contrib.admin or django.contrib.auth.

What is the fastest way to generate CRUD webpages for Google App Engine using Python?

I have created a set of Models for my database using Python. Now I'd like to rapidly load them with some data -- manually. If this were a .NET app, I'd use one of the nifty controls that come with Visual Studio to rapidly connect to the database and bind a grid to it. Then go to town adding data.
What's the matching way to do this in Python using Google App Engine?
In ASP.NET MVC, they have this new "scaffolding" stuff (part of Entity Framework) that will generate CRUD pages for you. Is there anything like that given a bunch of Model objects in GAE?
P.S. using the handy, dandy command line options --use_sqlite and --datastore_path, I can quickly backup my database in my dev environment once I do this.
If you are using Django on GAE then you can use the Django Administration site:
So what’s Django’s approach to these boring, repetitive tasks? It does
it all for you—in just a couple of lines of code, no less. With
Django, building an admin interface is a solved problem.
It automatically builds CRUD based HTML forms for managing the model.
Have a look to the appengine admin project.
Appengine Admin is simple python package that you can use for creating
automatic admin interface for your Google Appengine application.
Here is a screenshot:
and here is the quickstart tutorial.
After creating your models, simply adding this line of code:
# Register to admin site
appengine_admin.register(..your list of class Models definition)
and after have defined the proper route to the admin with:
(r'^(/admin)(.*)$', appengine_admin.Admin)
you can access to the customized admin that offers the following features:
List records for each registered model
Create new records
Update/edit records
Delete records
I'm still something of a python and GAE newbie, but I've been working with it a lot over the past few months so you might find that this works:
You can use Model.properties() to get the list of properties for the model in question and save it to a list. You can then add the list to the context dictionary for use in your template. In your template iterate over the loop to generate a basic list of input fields with the names matching each property.
{% for tItem in list %}
<input type="text" name="{{ tItem }}" />
{% endfor %}
Then you can post back to the same page, where you can use Request.arguments() to pair your object properties to your model for saving into the datastore.
To my knowledge there's not a much more elegant solution than that, at least not comparable to the ASP.NET MVC scaffolding that you're talking about.
(disclaimer: I've not actually tried this so there is likely a problem or two that needs to be sorted)
The trouble with Django on App Engine is you can't use the GAE datastore and ndb models (so the Django admin is not available), or you have to start using a hacked version of Django: http://django-nonrel.org/
Well probably for most apps you're better off using Cloud SQL anyway, which is basically MySQL so no prob with Django.
If you need to use the GAE datastore try this framework, which provides a CRUD admin:
http://ferris-framework.appspot.com/docs/index.html
You can check out Ferris Framework
which is tightly integrated to Google App engine and datastore.
Ferris Framework also has the scaffolding component for creating CRUD actions in a breeze.
http://ferris-framework.appspot.com/docs/users_guide/scaffolding.html?highlight=scaffolding

django on appengine

I am impressed with django.Am am currenty a java developer.I want to make some cool websites for myself but i want to host it in some third pary environmet.
Now the question is can i host the django application on appengine?If yes , how??
Are there any site built using django which are already hosted on appengine?
Django-nonrel is the best and "official" way to run django on appengine. You can run django apps unmodified on AppEngine (as long as there are no complex joins or ManyToMany relationships)
You also now have access to the full django admin which really is the best part of django.
http://code.google.com/appengine/articles/django.html
http://www.allbuttonspressed.com/projects/django-nonrel
http://code.google.com/appengine/articles/django.html
http://www.42topics.com/dumps/django/docs.html
http://thomas.broxrost.com/2008/04/08/django-on-google-app-engine/
Yes, its quite possible. The only difference is, instead of using django's models and database api you simply need to use appengine's datastore api and models. Look at the above links for reference
Appengine comes with built in Django, if you look under your (google_appengine/lib/django_1_3) lib dir you will see a few versions. You can define what version you want to be used in your app.yaml
It isn't a full release of Django and if you do want to have full admin functionality of Django you might have to use something like nonrel but personally I would say its not necessary and you stand to gain more by getting to understand the underlying nosql structure of appengine, in particular the NDB model is very useful

Categories

Resources