Skip to content

Latest commit

 

History

History
78 lines (56 loc) · 2.38 KB

README.md

File metadata and controls

78 lines (56 loc) · 2.38 KB

Django HTTP Model

A Django Manager for HTTP data using the well-known Django ORM interface

Build Status Coverage Status PyPI version Code Health GitHub license

Installation

This package is not in PyPI. We'll add as soon as possible

Usage

Imagine that you have an endpoint http://my.api.com/companies that shows a list of Companies:

[
    {
        "name": "Company 1",
        "id": 1,
        "nameOfFounder": "Marcos Cardoso",
        "birthday": "1990-07-30",
    },
    {
        "name": "Company 2",
        "id": 2,
        "nameOfFounder": "Samuel Medeiros Cardoso",
        "birthday": "1955-04-26",
    }
]

The first step is create a model class that inherit from HTTPModel, and setup the desired attributes and override the HTTPModel.HTTPMeta class:

from django_http_model.models import HTTPModel, fields

class Company(HTTPModel):

	name = fields.HTTPField()
	id = fields.HTTPField()
	founder = fields.HTTPField(field_name="nameOfFounder")
	birthday = fields.HTTPDateField(date_fmt="%Y-%m-%d")

	class HTTPMeta(HTTPModel.HTTPMeta):
		url = "http://my.api.com/companies"

Now you can call the manager methods from Company model: Company.objects.all(), for example.

Implemented methods

HTTPModel

  • delete/0

HTTPManager

  • all/0
  • get/1
    • pk: int
  • delete/1
    • pk: int

To do

  • Relations between HTTPModel
  • Relations between HTTPModel and django.db.models.Model
  • More manager's methods:
    • save/0
    • filter/1 [?]
      • pks: list

Changelog

dev:

  • HTTPModel, HTTPManager, HTTPField and HTTPDateField implemented
  • HTTPManager: all/0, get/1 and delete/1 method implemented
  • HTTPModel: delete/0 method implemented