Very simple proof-of-concept that uses the django.forms library (newforms) for validation, and formalchemy for saving the model instance using sqlalchemy.
it can be used like this (pseudo-code):
if form.is_valid(): form.save(session=Session, app_label='Contact')
Feel free to improve the concept. Ideally, either use formalchemy or django.forms but not both like this example. ;-)
1 2 3 4 5 6 7 8 9 10 11 12 | class ContactForm(forms.Form):
def save(self, session=None, app_label=None):
""" Save or update a new `Contact` """
# create this composite entity
_data = {}
for key,val in self.cleaned_data.items():
_data[app_label+'--%s' % key] = val
fs = FieldSet(Contact, session=session, data=_data)
if fs.validate():
fs.sync()
return None
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 1 week ago
- Serializer factory with Django Rest Framework by julio 1 year, 4 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 5 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
first snippet :-)
#
Please login first before commenting.