Thursday, June 29, 2017

Re: First models.py needs tuning


2017-06-29 18:07 GMT-03:00 Rich Shepard <rshepard@appl-ecosys.com>:
On Wed, 19 Apr 2017, Mike Dewhirst wrote:

Second, I have a couple of fields with postgres check constraints; that
is, valid data is restricted to a list of strings. I've not found a
Django model field validator teaching me how to write this.

Use the model's clean() method ...
https://docs.djangoproject.com/en/1.11/ref/models/instances/#django.db.models.Model.clean

  What I see in Model.clean is a validation check which returns an error
message to the user if the check fails. I understand using this in cases
where required data are missing (such as the example of a draft article not
having a blank publication date). What I don't see is how to write a
validation check for an attribute whose value should be limited to a list.

  Example: a table attribute (column) for 'industry' in which valid entries
are limited to a list such as 'Agriculture', 'Business, other', 'Chemicals',
'Energy', 'Law').

  In postgres SQL this would be a constraint check. How do I write this in a
django Model.clean or its relatives?

Rich

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOs3Lp6rtnJeT%3Do4QNE1EPKPwmiAUTvagyrEjJCyzg-wSYRDrg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment