2

I want to return these error messages to the html form and show where are wrong with this form.Is there a solution?Or maybe I should use raw SQL queries?Thanks for any advice.

For example:

models.py:

class GeneticCharacter(models.Model):
    StrainNo=models.CharField(max_length=10,primary_key=True)
    StrainName=models.CharField(max_length=10)
    SourceNo=models.IntegerField()
    ESBL=models.CharField(max_length=9,blank=True)
    AEM=models.CharField(max_length=12,blank=True)
    PMQR=models.CharField(max_length=15,blank=True)
    ISeq=models.CharField(max_length=12,blank=True)
    Replicon=models.CharField(max_length=10,blank=True)
    MLST_type=models.CharField(max_length=10,blank=True)
    PLG_type=models.CharField(max_length=2,blank=True)
    IsPat=models.BooleanField()

views.py

...
obj=GeneticCharacter()
obj.ESBL="a"*20
obj.AEM="a"*20
obj.save()
...

How can I catch all the exceptions?

3
  • Which Error messages..? Commented Oct 8, 2013 at 10:16
  • Such as a too long string for a CharField in the model Commented Oct 8, 2013 at 10:19
  • Can you be more specific? Can you provide us some code? Commented Oct 8, 2013 at 10:21

1 Answer 1

2

I guess you want a ModelForm. That takes care of the error handling for your model. Check out https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#modelform

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.