Git Product home page Git Product logo

xml_models2's Introduction

Build Status Coverage Status

Read The Docs

XmlModels2

XmlModels allows you to define Models similar in nature to Django models that are backed by XML endpoints rather than a database. Using a familiar declarative definition, the fields map to values in the XML document by means of XPath expressions. With support for querying external REST APIs using a django-esque approach, we have strived to make writing and using xml backed models as close to django database models as we can, within the limitations of the available API calls.

Installation

The simplest approach is to to use pip install xml_models2

A simple example

Just to get started, this is an example of taking an XML representation of an Address that might be returned from a GET request to an external REST api.

<Address id="2">
  <number>22</number>
  <street>Acacia Avenue</street>
  <city>Maiden</city>
  <country>England</country>
  <postcode>IM6 66B</postcode>
</Address>

class Address(xml_models.Model):
  id=xml_models.IntField(xpath="/Address/@id")
  number = xml_models.IntField(xpath="/Address/number")
  street = xml_models.CharField(xpath="/Address/street")
  city = xml_models.CharField(xpath="/Address/city")
  country = xml_models.CharField(xpath="/Address/country")
  postcode = xml_models.CharField(xpath="/Address/postcode")

  finders = {(id,): 'http://adresses/%s'}

This example would be used as follows:-

>>> address = Address.objects.get(id=2)
>>> print "address is %s, %s" % (address.number, address.street)
"22, Acacia Avenue"

Heritage

This project is a fork of Django REST Models

xml_models2's People

Contributors

g-ford avatar gnehcwu avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

xml_models2's Issues

function "unicode(string)" in xpath_finder.py seems no necessary

Data found/Extracted by lxml through xpath is already unicode type, there seems no need to convert manully using the decode functions in lib codecs, so i think this part is not necessary:

if sys.version < '3':
    def unicode(string):
        """
        Fake unicode function
        """
        import codecs
        if not string:
            return
        return codecs.unicode_escape_decode(string)[0]
else:
    def unicode(string):
        """
        Fake unicode function
        """
        return string

using it with forms

Hello I try ti ose it with modelforms and get error

python2.7/site-packages/django/forms/models.py", line 277, in __new__
    raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (surname,

this is models.py
surname = xml_models.CharField(max_length=32, verbose_name=u'Фамилия', db_index=True, xpath='surname')

how to fix this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.