On Mar 14, 8:04 am, Sergio <sergio....@gmail.com> wrote: > wow, that's interesting. I was not aware if this. > > So, coming to the real question, here is my use case which raised this > questions: > > I've a class in the model with two CharFields. When validating data > inputs, I need to check that, if the user filled field A, then also > field B should contains some value > > - model definition > > class MyClass(models.Model): > ... > A = models.CharField(max_length=20) > B = models.CharField(max_length=20) > ... > > - validation > ... > A = cleaned_data.get("A") > B = cleaned_data.get("B") > if A != "" and B == "": > self._errors["B"] = ErrorList(["B must be filled because A is > filled"]) > > is this ok and independent from all DB backends as opposed to (if A > is not None and B is None) which seems not work?
Yes, a form CharField will always represent an empty value as '', not None. Note that it shouldn't matter for your use case, though. The condition `if A and not B:` will work regardless of whether an empty value is '' or None. Regards, Ian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---