Luna is what I'm calling my project to take back my photos.
You can follow along with the code here: https://github.com/issackelly/luna
The repository and the data models are the first step in any code base.
I'm not yet going to cover many of the choices that I made in the project (pipenv, dj-database-url, celery, etc). In this installment, I'll be describing the folder structure and the basic model setup at backend/backend/models.py .
The top level of the repository looks like this:
There is one model that everything else sort of latches onto. That's the StoredFile model.
It's called StoredFile instead of "File" so it doesn't collide with other things named file.
I don't like model inheritance. I think it's generally clunky and difficult to think through, and it makes querying a pain. This is why I have one StoredFile models instead of one Video and one Photo model that inherite from a StoredFile model.
Let's start with just the attributes
I've overridden the default "id" attribute with a UUID. UUIDs are good because they are unique and can be generated at either the client or the server side without knowledge of the other, and without making your database care about consistency. They're also hard to guess. UUIDs are cool.
I've used a PointField from GeoDjango to store the latitude and longitude. This will let me use all of the neat GIS tools to query and display that later.
I'm storing the file itself as a Django "FileField". This is stored in the database as a path to the file, but the Django Model represents that as a richer type, and lets me treat it like it's a file handle that I can read/write from.
I'm also storing the sha of the file. This is so I can detect duplicates or see if the contents of the file have changed.
I have four timestamps. Two about the contents of the file (start and end) and two about the database row (created and modified)
Start and End are for files that have a point, or a span of time. A photo will have a point (when it was taken)
A video would have a span, or start and end.
"Created" references when it was put in the database
"Modified" references when the database record for this file was last edited.
There are also a couple of JSONFields to store miscellaneous records related to the file, or related to the processing of the file. Reasons for these fields will become clear later.
There are four methods on a StoredFile right now
The __str__ method could have been written as just "return self.content.name" but it's a habit.
This method is intended for things like the python REPL or the Django Admin to give a single string about the model instance
The check_sha method is a little under-developed right now, but it collects and stores the sha of the contents of the file. In the future I might want to do something else if the shas don't match, like store a version number, or save the old version of the file somewhere else.
The save method does the first few bits of metadata collection, for the sha, the filesize, and the mime_type.
It's likely that these will all get moved to a celery task later, instead of the model save method.
The serialize method will return a flat dictionary of a StoredFile instance that can be serialized into a simple JSON object for the API.
I find methods like this much easier to get started with than API layers like "Django rest framework"
An album is a collection of StoredFile objects with some idea of permissions about who can view and edit it.
A tag is a short word or phrase that can be associated with any StoredFile. It's for categorization
An event is either a point or span of time, also used for categorization.
15th June 2018
I won't ever give out your email address. I don't publish comments but if you'd like to write to me then you could use this form.
I'm Issac. I live in Oakland. I make things for fun and money. I use electronics and computers and software. I manage teams and projects top to bottom. I've worked as a consultant, software engineer, hardware designer, artist, technology director and team lead. I do occasional fabrication in wood and plastic and metal. I run a boutique interactive agency with my brother Kasey and a roving cast of experts at Kelly Creative Tech. I was the Director of Technology for Nonchalance during the The Latitude Society project. I was the Lead Web Developer and then Technical Marketing Engineer at Nebula, which made an OpenStack Appliance. I've been building things on the web and in person since leaving Ohio State University's Electrical and Computer engineering program in 2007. Lots of other really dorky things happened to me before that, like dropping out of high school to go to university, getting an Eagle Scout award, and getting 6th in a state-wide algebra competition. I have an affinity for hopscotch.