The snippet enables decoupling model classes, associated with a ForeignKey, for the purpose of separating them into two databases. Looking at the following example:
class Reporter(models.Model):
...
class Article(models.Model):
reporter = models.ForeignKey(Reporter)
We want to separate the `Reporter` and `Article` into two separate databases, but this won't work in Django because of the [cross model relations](http://docs.djangoproject.com/en/dev/topics/db/multi-db/#cross-database-relations). The solution is to use an ID field and not a `ForeignKey` one. This makes the access very uncomfortable. The above class will make this a bit less awkward. It doesn't support the [RelatedManager](http://docs.djangoproject.com/en/dev/ref/models/relations/#django.db.models.fields.related.RelatedManager), but it will support accessing the related field as you normally would.
The article class will look like this (assuming the reporter model id field is an `IntegerField`):
class Article(DecoupledModel):
reporter_id = models.IntegerField()
_linked_fields = {
'reporter': Reporter,
}
Once you have an article object, you can access the reporter as you normally would for both read and writing. For example:
my_reporter = article1.reporter
article2.reporter = my_reporter
Shows difference between two json like python objects. May help to test json response, piston API powered sites...
Shows properties, values from first object that are not in the second.
Example:
import simplejson # or other json serializer
first = simplejson.loads('{"first_name": "Poligraph", "last_name": "Sharikov",}')
second = simplejson.loads('{"first_name": "Poligraphovich", "pet_name": "Sharik"}')
df = Diff(first, second)
df.difference is ["path: last_name"]
Diff(first, second, vice_versa=True) gives you difference from both objects in the one result.
df.difference is ["path: last_name", "path: pet_name"]
Diff(first, second, with_values=True) gives you difference of the values strings.
- django
- json
- piston
- compare