I have a django project where I want to save web scraped data to the 
database via the django ORM- which will be used in the django app. 

The data is currently in the form of JSON -> converted to python dict via 
json.loads

I setup my model with the narrowest/ most constrained field type possible - 
(e.g. DecimalField with decimal_places=2 and max_digits=4 for prices)

I naively tried to save the data/values from the relevant keys in the JSON 
directly to the relevant model field, however, this raised errors due to 
data format.

It looks like data entered via a form is converted to the relevant python 
object in the form validation - e.g. a date string '24 May 2015' is 
converted to a datetime object and the date format validated.  

None of this appears to happen when saving directly to a model? (would be 
good to have my understanding here confirmed?) and so saving '24 May 2015' 
directly to a DateField in a model produces a format error. 

What validation (if any) does Django do when saving to a database directly 
via the ORM? - Does it just rely on the type checking in the database (so 
for sqlite this would be nothing but would for postgres)?

Thanks.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f5e1da4d-50af-4ded-8658-829413ab0c49%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to