douglas / django-fossil Goto Github PK
View Code? Open in Web Editor NEWThis is a fork of Bireme's django-fossil. The official repository is on: http://goo.gl/VJvi
This is a fork of Bireme's django-fossil. The official repository is on: http://goo.gl/VJvi
This is a pluggable application for projects based on Django framework and its ORM. This library stores fossilized revissions of objects and supports fossilized foreign keys. INSTALLING ---------- Just run "python setup.py install" or just put "fossil" package in PYTHONPATH. HOW TO USE IT ON YOUR PROJECT ----------------------------- 1. Add 'fossil' to INSTALLED_APPS of settings.py of your project 2. You can use FossilForeignKey fields as you can see below: from fossil.fields import FossilForeignKey class Supplier(models.Model): name = models.CharField(max_length=100) ... class Purchase(models.Model): ... supplier = FossilForeignKey(Supplier, null=True, blank=True) The model classe "Purchase" will work as usual, you can set Supplier object to the field 'supplier' but inside it will make a fossil revision for current version of this supplier and the relation will be made with it. Even if this object is deleted in the future, the relation will keep here with current data. 3. You can create and/or list manually fossils for objects, like below: from fossil.models import Fossil # Returns a new or existing fossil for object new_fossil = Fossil.objects.create_for_object(my_supplier) # Returns all fossils for a given object, ordered by creation date list_of_fossils = Fossil.objects.fossils_of_object(qualquer_objeto) HOW IT WORKS ------------ Django-fossil is stupdly simple. You don't need neither register a model class or inherit anyone. It will make a fossil for a given object basing on its serialization and will not duplicate revisions for object with same values. The serialization will be made using Django JSON serialization feature, but you can customize it implementing methods to serialize to string and deserialize to object, like below: from django.utils import simplejson from fossil.fields import FossilForeignKey class SupplierManager(models.Manager): def deserialize_for_fossil(self, data): json = simplejson.loads(data) return Supplier(name=json['name']) class Supplier(models.Model): objects = SupplierManager() name = models.CharField(max_length=100) def serialize_for_fossil(self): return simplejson.dumps({'name': self.name}) As you can see above, there are two methods, one to serialize and one to deserialize. The first one is as part of Model class and the second one is part of Manager class. So you can use your creativity to make them as you want.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.