Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big update. #3

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 104 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,104 @@
*.pyc
/build
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
.static_storage/
.media/
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: python
python:
- '3.5'
- '3.6'
install:
- pip install tox
script:
- tox
after_success:
- coveralls
deploy:
provider: pypi
user: "Samuel.Spencer"
password:
secure: IpJuYrTkutnCuIzI61JnXoP9qkCGvvmc0wE8oBIn9HFyhWVyPw2qbNTQp58lOMOf2UVm24c3iA3Pax+1J8g9q9N144rMkgBpg5dot8KT3mt9u5TDupnKiLLl66IFh2/B68MTbx33ZCu6rCNAE49wlKGdRAf7EWIXVMJ1D7bzjtC0L5aTtML1yOc0sbsXxpFr3D0jkxP5VsTulPkKIbUrjYkphNWSLc4kobapqCwRE8tLvd50obJjl/IqGv1K+19l2TNiniDETB7R48fRenZkOIVG97y0yUP4EM71mxATU4pb/UpbenpzkhpUM+VsnUMTRht8p85Yn736m/wEmef6rCz5wccdusRW5pwy/+fJcGjci6f3Y+nWM7ZNsFmV9TvKYEhRbHWknNPWohRqSuuBHYEnX5jzosBIij1TDSpNJUXvs9GTQfSGwlEyviJUmX6f2Km1K2fdqw5FkXR9tUJyt8ezdfm4bc13DfDpeb5W1m/8dkE8ulO7TS4yp9KXqBYjkn5CduhU75lwZ+lhKfEbEzUrqoAyf4p/6wLV6J8YeEn7+BdmNp8m7lXUxZ21sIv6XacihdsGG1pqoqNNjlTLx2zm7ygtm3OyVFvz21aXBZAaGzlVeWaOcgyDMlEW+rveQ6MVgAydevX+ztzFpUCJEi2xYDTCZwt+1emFrjNWWms=
on:
branch: master
condition: $TRAVIS_PYTHON_VERSION == 3.6
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include LICENSE
include README.rst
recursive-include database_files/ *
exclude MANIFEST.in
40 changes: 0 additions & 40 deletions README.md

This file was deleted.

48 changes: 48 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
django-database-files
=====================

.. image:: https://travis-ci.org/LegoStormtroopr/django-database-files.svg?branch=master
:target: https://travis-ci.org/LegoStormtroopr/django-database-files

``django-database-files`` is a storage system for Django that stores files in the database.
It can act as a storage class anywhere that accepts the `Django storage API <https://docs.djangoproject.com/en/2.0/ref/files/storage/>`_.

WARNING: There are serious downsides to storing and serving static files from Django,
but there are some valid use cases.

If your Django app is behind a caching reverse proxy and you need to scale your
application servers, it may be simpler to store files in the database.

Likewise, when using systems like Heroku where no easy and persistent file system
exists, storing files in the database can provide a quick way to add file management.


Requires:

* Django 1.11 or above only
* Python 3.5 or above only

Installation
------------

$ pip install django-database-files-ny

Usage
-----

In ``settings.py``, add ``database_files`` to your ``INSTALLED_APPS`` and add this line::

DEFAULT_FILE_STORAGE = 'database_files.storage.DatabaseStorage'

In your ``urls.py`` add a path to the database files::

url(r'^db_static/', include("database_files.urls")),

All your ``FileField`` and ``ImageField`` files will now be stored in the
database.

Test suite
----------

$ tox

1 change: 1 addition & 0 deletions database_files/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
import os


class FileManager(models.Manager):
def get_from_name(self, name):
return self.get(pk=os.path.splitext(os.path.split(name)[1])[0])
58 changes: 25 additions & 33 deletions database_files/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-02-23 02:40
from __future__ import unicode_literals

from south.db import db
from django.db import models
from database_files.models import *
from django.db import migrations, models

class Migration:

def forwards(self, orm):

# Adding model 'File'
db.create_table('database_files_file', (
('id', orm['database_files.File:id']),
('content', orm['database_files.File:content']),
('size', orm['database_files.File:size']),
))
db.send_create_signal('database_files', ['File'])



def backwards(self, orm):

# Deleting model 'File'
db.delete_table('database_files_file')



models = {
'database_files.file': {
'content': ('django.db.models.fields.TextField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'size': ('django.db.models.fields.IntegerField', [], {})
}
}

complete_apps = ['database_files']

class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='FileInDatabase',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField(unique=True)),
('size', models.IntegerField()),
('created_at', models.DateTimeField(auto_now_add=True)),
('modified_at', models.DateTimeField(auto_now=True)),
('content', models.BinaryField()),
],
),
]
11 changes: 7 additions & 4 deletions database_files/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from django.db import models
from database_files.manager import FileManager

class File(models.Model):
content = models.TextField()

class FileInDatabase(models.Model):
name = models.TextField(unique=True)
size = models.IntegerField()

objects = FileManager()
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)
content = models.BinaryField()

objects = FileManager()
Loading