Skip to main content

Mapping annotated dict list into Django models

Project description

https://travis-ci.org/lqez/django-d2m.svg?branch=master https://img.shields.io/coveralls/lqez/django-d2m.svg

Mapping annotated dict list into Django models

Usage

Wrap your django queryset or list with django-d2m functions

from django_d2m import queryset_to_model

queryset = CashUsageLog.objects.values('product__episode__comic').annotate(cash_used=Sum('cash'))
i_want_real_objects = queryset_to_model(queryset)

# You can convert just a dict
from django_d2m import dict_to_model
dict_to_model(some_dict_contains_only_id, MyModel)

# Or, for list
from django_d2m import list_to_model
list_to_model(some_dict_list, YourModel)

Before

{'product__episode__comic': 10L, 'cash_used': 3100}
{'product__episode__comic': 7L, 'cash_used': 1100}
{'product__episode__comic': 15L, 'cash_used': 800}

After

{'product__episode__comic': <Comic: 다즐짱>, 'cash_used': 3100}
{'product__episode__comic': <Comic: 파이일기>, 'cash_used': 1100}
{'product__episode__comic': <Comic: 스카리의 유희>, 'cash_used': 800}

Install

pip install django-d2m

License

MIT

Author

@lqez

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-d2m-0.1.4.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file django-d2m-0.1.4.tar.gz.

File metadata

  • Download URL: django-d2m-0.1.4.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-d2m-0.1.4.tar.gz
Algorithm Hash digest
SHA256 daf2604fad2f5e07fcbcae22db8641092dc62df4f5577ad8b0d1b20245a52411
MD5 535e3b1399ecbb63a33ea289e51898fa
BLAKE2b-256 0f2ac264c0f1873b80973278d751da502670881343f5f81ec247d56cf6e00cf6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page