-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
844 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
This is a sample XSD from http://www.datypic.com/books/defxmlschema/chapter04.html. | ||
|
||
The resulting models look fairly well. Additional XSD files are automatically imported using `xs:import[@schemaLocation]` and `xs:include[@schemaLocation]`. | ||
|
||
The settings file demonstrates: | ||
* XSD typename to Django model name mapping (`TYPE_MODEL_MAP`). | ||
* `flatten_fields` usage for `xs:complexType/xs:simpleContent/xs:extension` fields. | ||
* `flatten_fields` usage for `xs:complexType/xs:complexContent` fields. | ||
|
||
PYTHONPATH=. ../../../xsd_to_django_model/xsd_to_django_model.py chapter04ord1.xsd OrderType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<xs:complexType name="CustomerType"> | ||
<xs:sequence> | ||
<xs:element name="name" type="CustNameType"/> | ||
<xs:element name="number" type="xs:integer"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
<xs:simpleType name="CustNameType"> | ||
<xs:restriction base="xs:string"/> | ||
</xs:simpleType> | ||
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
targetNamespace="http://example.org/ord" | ||
xmlns="http://example.org/ord" | ||
xmlns:prod="http://example.org/prod"> | ||
<xs:include schemaLocation="chapter04ord2.xsd"/> | ||
<xs:include schemaLocation="chapter04cust.xsd"/> | ||
<xs:import namespace="http://example.org/prod" | ||
schemaLocation="chapter04prod.xsd"/> | ||
<xs:element name="order" type="OrderType"/> | ||
<xs:complexType name="OrderType"> | ||
<xs:sequence> | ||
<xs:element name="number" type="OrderNumType"/> | ||
<xs:element name="customer" type="CustomerType"/> | ||
<xs:element name="items" type="prod:ItemsType"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns="http://example.org/ord" | ||
targetNamespace="http://example.org/ord"> | ||
<xs:simpleType name="OrderNumType"> | ||
<xs:restriction base="xs:string"/> | ||
</xs:simpleType> | ||
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns="http://example.org/prod" | ||
targetNamespace="http://example.org/prod"> | ||
<xs:complexType name="ItemsType"> | ||
<xs:sequence> | ||
<xs:element name="product" type="ProductType"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
<xs:complexType name="ProductType"> | ||
<xs:sequence> | ||
<xs:element name="number" type="xs:integer"/> | ||
<xs:element name="name" type="xs:string"/> | ||
<xs:element name="size" type="SizeType"/> | ||
<xs:element name="color" type="ColorType"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
<xs:complexType name="SizeType"> | ||
<xs:simpleContent> | ||
<xs:extension base="xs:integer"> | ||
<xs:attribute name="system" type="xs:string"/> | ||
</xs:extension> | ||
</xs:simpleContent> | ||
</xs:complexType> | ||
<xs:complexType name="ColorType"> | ||
<xs:attribute name="value" type="xs:string"/> | ||
</xs:complexType> | ||
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# THIS FILE IS GENERATED AUTOMATICALLY. DO NOT EDIT | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
|
||
import datetime | ||
from django.core import validators | ||
from django.db import models | ||
|
||
|
||
class CustNameTypeField(models.TextField): | ||
# Simple exact redefinition of TextField parent! | ||
pass | ||
|
||
class OrderNumTypeField(models.TextField): | ||
# Simple exact redefinition of TextField parent! | ||
pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# THIS FILE IS GENERATED AUTOMATICALLY. DO NOT EDIT | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
|
||
import datetime | ||
from django.core import validators | ||
from django.db import models | ||
|
||
from .fields import \ | ||
CustNameTypeField, \ | ||
OrderNumTypeField | ||
|
||
|
||
|
||
# Corresponds to XSD type[s]: CustomerType | ||
class Customer(models.Model): | ||
name = CustNameTypeField("name") | ||
number = models.IntegerField("number") | ||
|
||
|
||
# Corresponds to XSD type[s]: prod:ProductType | ||
class Product(models.Model): | ||
number = models.IntegerField("number") | ||
name = models.TextField("name") | ||
size_system = models.TextField("size::size_system", null=True) | ||
size = models.IntegerField("size") | ||
color_value = models.TextField("color::color_value", null=True) | ||
|
||
|
||
# Corresponds to XSD type[s]: prod:ItemsType | ||
class Items(models.Model): | ||
product = models.ForeignKey( | ||
Product, | ||
on_delete=models.PROTECT, | ||
verbose_name="product" | ||
) | ||
|
||
|
||
# Corresponds to XSD type[s]: OrderType | ||
class Order(models.Model): | ||
number = OrderNumTypeField("number") | ||
customer = models.ForeignKey( | ||
Customer, | ||
on_delete=models.PROTECT, | ||
verbose_name="customer" | ||
) | ||
items = models.ForeignKey( | ||
Items, | ||
on_delete=models.PROTECT, | ||
verbose_name="items" | ||
) | ||
|
||
|
10 changes: 10 additions & 0 deletions
10
examples/defxmlschema/chapter04/xsd_to_django_model_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
TYPE_MODEL_MAP = { | ||
r'prod:(.+)Type': r'\1', | ||
r'(\w+)Type': r'\1', | ||
} | ||
|
||
MODEL_OPTIONS = { | ||
'Product': { | ||
'flatten_fields': ['color', 'size'] | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
This is a sample XSD from http://www.datypic.com/books/defxmlschema/chapter05.html. | ||
|
||
The settings file demonstrates: | ||
* XSD typename to Django model name mapping (`TYPE_MODEL_MAP`). | ||
* `many_to_many_fields` usage. | ||
* `primary_key` usage. | ||
* `flatten_fields` usage for `xs:complexType/xs:simpleContent/xs:extension` fields. | ||
|
||
An extra technique is demonstrated for different namespaces in multiple XSD files: a manually crafted "root" XSD file, `chapter05.xsd`, with `schemaLocation` references. | ||
|
||
The resulting models look fairly well. | ||
|
||
PYTHONPATH=. ../../../xsd_to_django_model/xsd_to_django_model.py chapter05.xsd OrderType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- manual hack to merge multiple xsd files - Ph. --> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:prod="http://example.org/prod"> | ||
<xs:import namespace="http://example.org/ord" schemaLocation="chapter05ord.xsd"/> | ||
<xs:import namespace="http://example.org/prod" schemaLocation="chapter05prod.xsd"/> | ||
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
targetNamespace="http://example.org/ord" | ||
xmlns="http://example.org/ord" | ||
xmlns:prod="http://example.org/prod"> | ||
<xs:import namespace="http://example.org/prod"/> | ||
<xs:element name="order" type="OrderType"/> | ||
<xs:complexType name="OrderType"> | ||
<xs:sequence> | ||
<xs:element name="items" type="ItemsType"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
<xs:complexType name="ItemsType"> | ||
<xs:sequence> | ||
<xs:element ref="prod:product" maxOccurs="unbounded"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns="http://example.org/prod" | ||
targetNamespace="http://example.org/prod"> | ||
<xs:element name="product" type="ProductType"/> | ||
<xs:complexType name="ProductType"> | ||
<xs:sequence> | ||
<xs:element name="number" type="xs:integer"/> | ||
<xs:element name="name" type="xs:string"/> | ||
<xs:element name="size" nillable="true" type="SizeType"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
<xs:complexType name="SizeType"> | ||
<xs:simpleContent> | ||
<xs:extension base="xs:integer"> | ||
<xs:attribute name="system" type="xs:string"/> | ||
</xs:extension> | ||
</xs:simpleContent> | ||
</xs:complexType> | ||
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# THIS FILE IS GENERATED AUTOMATICALLY. DO NOT EDIT | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
|
||
import datetime | ||
from django.core import validators | ||
from django.db import models | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# THIS FILE IS GENERATED AUTOMATICALLY. DO NOT EDIT | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
|
||
import datetime | ||
from django.core import validators | ||
from django.db import models | ||
|
||
|
||
|
||
|
||
# Corresponds to XSD type[s]: prod:ProductType | ||
class Product(models.Model): | ||
number = models.IntegerField("number", primary_key=True) | ||
name = models.TextField("name") | ||
size_system = models.TextField("size::size_system", null=True) | ||
size = models.IntegerField("size") | ||
|
||
|
||
# Corresponds to XSD type[s]: OrderType | ||
class Order(models.Model): | ||
items = models.ManyToManyField(Product, verbose_name="items") | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
examples/defxmlschema/chapter05/xsd_to_django_model_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
TYPE_MODEL_MAP = { | ||
r'prod:(.+)Type': r'\1', | ||
r'(\w+)Type': r'\1', | ||
} | ||
|
||
MODEL_OPTIONS = { | ||
'Order': { | ||
'many_to_many_fields': ['items'], | ||
}, | ||
'Product': { | ||
'flatten_fields': ['size'], | ||
'primary_key': 'number', | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This is a sample XSD from http://www.datypic.com/books/defxmlschema/chapter06.html. | ||
|
||
The resulting model looks fairly well. | ||
|
||
PYTHONPATH=. ../../../xsd_to_django_model/xsd_to_django_model.py chapter06.xsd ProductType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns="http://example.org/prod" | ||
targetNamespace="http://example.org/prod" | ||
elementFormDefault="qualified"> | ||
<xs:element name="product" type="ProductType"/> | ||
<xs:element name="size" type="xs:integer" fixed="10"/> | ||
<xs:complexType name="ProductType"> | ||
<xs:sequence> | ||
<xs:element name="name" default="N/A"> | ||
<xs:simpleType> | ||
<xs:restriction base="xs:string"> | ||
<xs:minLength value="1"/> | ||
</xs:restriction> | ||
</xs:simpleType> | ||
</xs:element> | ||
<xs:element ref="size" minOccurs="0"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# THIS FILE IS GENERATED AUTOMATICALLY. DO NOT EDIT | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
|
||
import datetime | ||
from django.core import validators | ||
from django.db import models | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# THIS FILE IS GENERATED AUTOMATICALLY. DO NOT EDIT | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
|
||
import datetime | ||
from django.core import validators | ||
from django.db import models | ||
|
||
|
||
|
||
|
||
# Corresponds to XSD type[s]: ProductType | ||
class ProductType(models.Model): | ||
name = models.TextField("name", blank=False, default='N/A') | ||
size = models.IntegerField("size", default=10, null=True) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This is a sample XSD from http://www.datypic.com/books/defxmlschema/chapter07.html. | ||
|
||
The resulting model looks fairly well. | ||
|
||
PYTHONPATH=. ../../../xsd_to_django_model/xsd_to_django_model.py chapter07.xsd SizeType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns="http://example.org/prod" | ||
targetNamespace="http://example.org/prod" | ||
elementFormDefault="qualified"> | ||
<xs:element name="size" type="SizeType"/> | ||
<xs:complexType name="SizeType"> | ||
<xs:attribute name="system" type="xs:string" use="required"/> | ||
<xs:attribute ref="dim"/> | ||
<xs:attribute name="value" default="10"> | ||
<xs:simpleType> | ||
<xs:restriction base="xs:integer"> | ||
<xs:minInclusive value="2"/> | ||
<xs:maxInclusive value="20"/> | ||
</xs:restriction> | ||
</xs:simpleType> | ||
</xs:attribute> | ||
</xs:complexType> | ||
<xs:attribute name="dim" type="xs:integer" fixed="1"/> | ||
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# THIS FILE IS GENERATED AUTOMATICALLY. DO NOT EDIT | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
|
||
import datetime | ||
from django.core import validators | ||
from django.db import models | ||
|
||
|
Oops, something went wrong.