tuffnatty / xsd_to_django_model

Generate Django models from an XSD schema description (and a bunch of hints)
GNU General Public License v3.0
25 stars 11 forks source link

Use basic (incomplete) DateField for xs:gYearMonth datatype. #2

Closed DrMattChristian closed 7 years ago

DrMattChristian commented 7 years ago

I'm open to better handling of the xs:gYearMonth XSD data type since it doesn't cleanly map into a Django DateField.

xsd:gYearMonth Datatype Reference

Without this minor code change, the Python interpreter crashes due to an assert.

xsd_to_django_model.py:586: assert type(options) is dict, "options is not a dict"

Example XSD input fragment to reproduce:

<xs:simpleType name="YearMonth">
<xs:restriction base="xs:gYearMonth"/>
</xs:simpleType>

I created a simple class-based YearMonthDateField that subclasses DateField. I can provide that Python code if it would help. In my custom field, the day is always overridden to 1 and ignored. The string output format is YYYY-MM (no day). The rest of the normal DateField validation is left intact.

More minor changes:

tuffnatty commented 7 years ago

@DrMattChristian Thanks! If you rebase your patch against the current master, bumping the version to 0.7.4 (or removing that change altogether), I will happily merge it.

DrMattChristian commented 7 years ago

@tuffnatty Yes I just rebased my PR onto your latest upstream master. I eliminated the version change entirely, now just one file change. You can bump/tag the main version as you see fit.

Thanks in advance for merging my simple change into upstream so I don't have to carry it separately.