Thank you so much. ср, 30 июн. 2021 г. в 18:43, 'Adam Johnson' via Django developers (Contributions to Django itself) <django-developers@googlegroups.com>:
> "Unique restriction will be ignored" - this is not the case. Uniqueness is > enforced by the database, so as long as your migrations have been built and > run correctly, the database will error when trying to insert a duplicate > unique value. If you're finding that you can create duplicates on unique > fields, check your database setup. > > For the case of checking whether a string contains a certain character, or > matches a format, it's possible to enforce in the database with a check > constraint. I've written several blog posts on the topic: > https://duckduckgo.com/?sites=adamj.eu&q=check+constraints&ia=web . None > exactly align with such string validation, but if you understand the > concepts you should be able to figure it out. Admittedly it's more > complicated than writing a validator function. > > On Wed, 30 Jun 2021 at 16:00, Args Kwargs <crazytheo...@gmail.com> wrote: > >> Here's what I mean: >> >> ср, 30 июн. 2021 г. в 16:45, 'Adam Johnson' via Django developers >> (Contributions to Django itself) <django-developers@googlegroups.com>: >> >>> What validation do you need? Much can be done in the database with >>> constraints, especially check constraints. >>> >>> On Wed, 30 Jun 2021 at 08:05, Михаил Итпрогер <crazytheo...@gmail.com> >>> wrote: >>> >>>> Hello, I am currently developing a reusable application using the >>>> Django framework. >>>> >>>> It just so happens that the instances of the models of this application >>>> will most often be created inside the code, and not in the forms. >>>> I've created validators for fields that only work in forms, but I would >>>> like to reuse them for creating/updating objects as well. >>>> The Django documentation says that validation only occurs on forms, but >>>> it is not written for what reason. >>>> >>>> I have tried many solutions to deal with this problem, but they all >>>> have a significant drawback - when creating an instance from a form, the >>>> validation happens twice. >>>> >>>> For example, with __setattr__(): once when the concstruct_instance() >>>> is called, the second time when full_clean(). >>>> >>>> With save(): first full_clean(), and then my validation in save(). >>>> I'm really interested in why the opportunity to validate everything at >>>> the object level was missed, because when creating objects outside the >>>> forms, you can enter any values into the fields that contradict the >>>> restrictions. >>>> >>>> I could solve this problem, which would require small changes in the >>>> validation logic, but first I need to consult with you. >>>> >>>> Besides, maybe you can tell me an alternative solution. >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Django developers (Contributions to Django itself)" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to django-developers+unsubscr...@googlegroups.com. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/django-developers/E619D0E2-3B55-478F-895B-0F59848BAFA6%40hxcore.ol >>>> <https://groups.google.com/d/msgid/django-developers/E619D0E2-3B55-478F-895B-0F59848BAFA6%40hxcore.ol?utm_medium=email&utm_source=footer> >>>> . >>>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Django developers (Contributions to Django itself)" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to django-developers+unsubscr...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-developers/CAMyDDM30TzCLFMsktSLEnZjUhr6f4FsF7eg%3DpzcFqmSLyO0sfA%40mail.gmail.com >>> <https://groups.google.com/d/msgid/django-developers/CAMyDDM30TzCLFMsktSLEnZjUhr6f4FsF7eg%3DpzcFqmSLyO0sfA%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django developers (Contributions to Django itself)" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-developers+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-developers/CANvv8_9YHZ2_e0UrfG8bzWUZkvm2e5N0L76RuS2X_bDtTF%2BK5Q%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-developers/CANvv8_9YHZ2_e0UrfG8bzWUZkvm2e5N0L76RuS2X_bDtTF%2BK5Q%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/CAMyDDM0L%3DUrajOp04YdrKLjMKw_RsgiiLioUXExr0a%3DT-JJyyw%40mail.gmail.com > <https://groups.google.com/d/msgid/django-developers/CAMyDDM0L%3DUrajOp04YdrKLjMKw_RsgiiLioUXExr0a%3DT-JJyyw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CANvv8_95rXqPUi_TkgjvvQH50LurpJJkVTWnmQfXEypn9ZmGTQ%40mail.gmail.com.