Package: djangobible
djangobibleThe djangobible library is a Django app that wraps thepythonbiblelibrary and provides models, managers, and other tools to easily index an object by a scripture reference.Latest VersionLicenseTestsCode QualitySupported Python/Django VersionsInstallationPip install the djangobible library.pipinstalldjangobibleAdd djangobible to your Django project'sINSTALLED_APPSsetting:INSTALLED_APPS=[...,# other apps"djangobible",]Run the django migrations for djangobible./manage.pymigratedjangobibleSettingsThere currently are no settings (other than INSTALLED_APPS) related to the djangobible project. In the future, it would be nice to have settings that determine things like the available versions of the Bible and the default version.Also, once support is implemented for multiple locales and languages, there could be related settings for that functionality.FeaturesThe djangobible library is a complete wrapper for thepythonbiblelibrary, so importing the djangobible library as:importdjangobibleasbiblewill provide all the same functionality as importing the pythonbible library as:importpythonbibleasbibleThis includes features such as:Searching text for Scripture referencesConverting a normalized scripture reference into a list of integer verse idsConverting a list of verse id integers into a list of normalized scripture referencesConverting a list of normalized scripture references into a formatted string scripture referenceRetrieving the Biblical text (in one or more open-source or public domain versions) for a given verse ID integerFor more information, see thepythonbible documentation.In addition, the djangobible library includes the following features:Template TagsThere are currently two template tags provided by the djangobible library:verse_referenceandverse_text.verse_referenceTheverse_referencetemplate tag, given a verse ID and a Bible version, returns the appropriate Scripture reference string.For example, givenverse_id = 1001001andversion = djangobible.Version.KING_JAMES, the following snippet from a Django template:{% load verse_tags %}
...
{% verse_reference verse_id version=version %}would display:Genesis 1:1The version parameter is optional, and the current default is King James, though that will ideally be configurable in the future.There is another optional parameter,full_title, which is a boolean flag to determine whether to display the long version or the short version of the book of the Bible title. It defaults toFalse, which displays the short version. For example, givenverse_id = 1001001andversion = djangobible.Version.KING_JAMESandfull_title = True, the following snippet from a Django template:{% load verse_tags %}
...
{% verse_reference verse_id version=version full_title=full_title %}would display:The First Book of Moses, called Genesis 1:1verse_textTheverse_texttemplate tag, given a verse ID and a Bible version, returns the appropriate text of that Bible verse.For example, givenverse_id = 1001001andversion = djangobible.Version.KING_JAMES, the following snippet from a Django template:{% load verse_tags %}
...
{% verse_text verse_id %}would display:In the beginning God created the heaven and the earth.The version parameter is optional, and the current default is King James, though that will ideally be configurable in the future.One-to-many style relationships between verses and Django modelsFor situations where an instance of a Django model needs to be associated with a single verse, that Django model can have a field of typeVerseField.For example:fromdjango.dbimportmodelsimportdjangobibleasbibleclassMyModel(models.Model):...# other fieldsverse=bible.VerseField()The underlying implementation ofVerseFieldis anIntegerFieldwhich stores the verse ID of the associated verse.Having this custom field type provides several benefits:The Django admin (and Wagtail) form contains a text field for the verse rather than an integer field and allows the user to enter the Scripture reference text rather than the verse id, which they may not know. It then validates that text to ensure it references one, and only one, verse.As just mentioned, this allows for validation, not only that the value is one, and only one, verse id, but that it is also a valid verse id (i.e. that it represents a book, chapter, and verse of the Bible that actually exists).More readable query filters (e.g.MyModel.objects.filter(verse=1001001)is valid, but so isMyModel.objects.filter(verse="Genesis 1:1")).You can set the verse field with either the int verse ID or the string reference:my_object=MyModel.objects.create(name="my object")my_object.verse=1001001my_object.save()ormy_object=MyModel.objects.create(name="my object")my_object.verse="Genesis 1:1"my_object.save()You can filter the objects in the query set by either the int verse ID or the string reference:MyModel.objects.filter(verse=1001001)orMyModel.objects.filter(verse="Genesis 1:1")In any of the above examples, if the verse is not a valid verse ID integer or string reference for a single verse, then aValidationErrorwill be raised.Many-to-many style relationships between verses and Django modelsWARNING: This is still a work in progress, and this functionality does not yet exist in a stable form.There are situations where an instance of a Django model needs to be associated with multiple verses. The current intended solution, inspired by thedjango-taggitlibrary, is to implement this feature in such a way that you would add this relationship to your model like:fromdjango.dbimportmodelsimportdjangobibleasbibleclassMyModel(models.Model):...# other fieldsverses=bible.VerseManager()Then you could add, remove, and reference those verses with something like:>>> my_object = MyModel.objects.create(name="My Object")
>>> my_object.verses.add("Genesis 1:1-3")
>>> my_object.verses.all()
[<Verse: Genesis 1:1>, <Verse: Genesis 1:2>, <Verse: Genesis 1:3>]
>>> my_object.verses.remove("Genesis 1:2")
>>> my_object.verses.all()
[<Verse: Genesis 1:1>, <Verse: Genesis 1:3>]
>>> MyModel.objects.filter(verses__in=[1001001])
[<MyModel: My Object>]Ideally, the form field would be a text field where the user could enter a list of Scripture references (e.g. "Genesis 1:1,3-10;Psalm 119;Luke 2:1-18;John 3:16")