Sync remote API resources to Django models
Reason this release was yanked:
wrong version
Project description
Django remote resources
Sync remote API resources to Django models
Quick start
pip install django-remote-resources
Add AbstractRemoteResource
to your model (1), and define a mapping between the fields in the remote data to your
model's fields (2), and create a custom QuerySet manager for the model, inheriting from RemoteResourceQuerySet
and
define method get_remote_data_iterator
(3). Optionally define a remote_data_key_field
that points to a unique
identifier on the remote data (4).
class ResourceMirrorQuerySet( # (3)
RemoteResourceQuerySet
):
def get_remote_data_iterator(self, *args, **kwargs):
client = RemoteClient()
return client.get_data(**kwargs) # should return an iterator, with each item representing a page of data
class ResourceMirror(
AbstractRemoteResource, # (1)
models.Model
):
remote_id = models.CharField(max_length=255)
name = models.CharField(max_length=255)
email = models.EmailField()
objects = ResourceMirrorQuerySet.as_manager() # (3)
remote_to_model_fields_map = { # (2)
'id': 'remote_id',
'name': 'name',
'email': 'email',
}
remote_data_key_field = 'id' # (4)
Development and Testing
IDE Setup
Add the example
directory to the PYTHONPATH
in your IDE to avoid seeing import warnings in the tests
modules. If
you are using PyCharm, this is already set up.
Running the Tests
Install requirements
pip install -r requirements.txt
For local environment
pytest
For all supported environments
tox
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-remote-resources-0.3.0rc0.tar.gz
.
File metadata
- Download URL: django-remote-resources-0.3.0rc0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7ab17146b689972c1c81a2200a6e902618b1c089187378d37ee1bdc0b4bcd0d |
|
MD5 | a540acf480c99e5d65312a4e22492350 |
|
BLAKE2b-256 | 844aded56f0eb17d376008f24bb3088ae6c5a5ca9501a22767159ecf3c905cc0 |
File details
Details for the file django_remote_resources-0.3.0rc0-py3-none-any.whl
.
File metadata
- Download URL: django_remote_resources-0.3.0rc0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f999b2aa7e74307931c6420d42b411593bba8e0b64419903b92470d50fbedfa5 |
|
MD5 | 484b4c7f1638d6937fbdf963f3cb1a69 |
|
BLAKE2b-256 | e6e6894f21ab38d88b6c53861a03020241a5e9d23bfc37ddc71aafe79cf9b0a2 |