Package: django-firebase-orm
django-firebase-orm.Django like models for NoSQL database Firestore Integrating with
django's ORM. This is a fork and improvement offirebase_ormproject which
was initially forked fromxavx0zand
stopped maintaining it.I made a few changes and improvements to suit my liking:Changed the need of creating a second settings.py file in the root
of your django project to now only require that you define the
neccessary configurations in your project's settings module.Note
that django is now an explicit dependencyCreated a new package for this app on pypi underdjango-firebase-ormIt is my desire to continue the development of this project and thus
welcome all developers wishing to contribute via improving
documentation, bug fixes, test coverage, new features, etc.Installation$pipinstalldjango-firebase-ormInitializeIn your project settings add the following configuration variablessettings.pyFIREBASE_ORM_CERTIFICATE='path/to/serviceAccountKey.json'FIREBASE_ORM_BUCKET_NAME='<BUCKET_NAME>.appspot.com'FIREBASE_ORM_CERTIFICATE:   Once you have created aFirebase
consoleproject
and downloaded a JSON file with your service account credentials.FIREBASE_ORM_BUCKET_NAME:   The bucket name must not contain gs:// or any other protocol
prefixes. For example, if the bucket URL displayed in theFirebase
consoleis
gs://bucket-name.appspot.com, pass the string
bucket-name.appspot.comUsageCreate model:fromfirebase_ormimportmodelsclassArticle(models.Model):headline=models.TextField()type_article=models.TextField(db_column='type')classMeta:db_table='medications'def__str__(self):returnself.headlineUsing The API:Creating objectsTo represent cloud firestore data in Python objects, FirebaseORM uses an
intuitive system: Amodelclassrepresents acollection, and aninstanceof that class represents adocumentin collection.To create an object, instantiate it using keyword arguments to the model
class, then call save() to save it to the database.# Import the models we created>>>frommodelsimportArticle# Create a new Article.>>>a=Article(headline='Django is cool')# Save the object into the database. You have to call save() explicitly.>>>a.save()Retrieving all objectsThe simplest way to retrieve documents from a collections is to get all
of them. To do this, use the all() method on a Manager as you would in
normal django:>>>all_Article=Article.objects.all()The all() method returns a list instance Article of all the collection
in the database.# Now it has an ID.>>>a.id1# Fields are represented as attributes on the Python object.>>>a.headline'Django is cool'Saving changes to objectsTo save changes to an object that's already in the database, use save().Given a Article instance a that has already been saved to the database,
this example changes its name and updates its record in the database:>>>a.headline='Django-Firebase-ORM is awesome'>>>a.save()This performs an document.update() method behind the scenes. FirebaseORM
doesn't hit the database until you explicitly call save().# Firebase ORM provides a rich database lookup API.>>>Article.objects.get(id=1)<Article: Django-Firebase-ORM is awesome>>>>Article.objects.get(id=2)Traceback (most recent call last):...DoesNotExist:Article matching query does not exist.Field options:The following arguments are available to all field types. All are
optional.Field.db_columnIf contains characters that aren't allowed in Python variable names --
use db_column. The name of the firestore key in document to use for
this field. If this isn't given, FirebaseORM will use the field's
name.Field types:AutoFieldclass AutoField()By default, FirebaseORM gives each model the following field:id=models.AutoField(primary_key=True)TextField**class TextField(**options)**Text string Up to 1,048,487 bytes (1 MiB - 89 bytes). Only the first
1,500 bytes of the UTF-8 representation are considered by queries.TextField has not extra required argument.Dependenciesfirebase-admingrpciodjangoBuilding from Source for Developers$gitclonehttps://github.com/TralahM/django-firebase-orm.git$cddjango-firebase-ormContributingSee the Contributing FileSee the Pull Request FileLICENCERead the license hereCREDITSThanks tojoewalk102for forking the
original project without whom this project would not be possible.Self-Promotion