HackSoftware / Django-Styleguide

Django styleguide used in HackSoft projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Validation with related models

timofeiryko opened this issue · comments

Hello. You suggest to use services for validation and call it from admin. But it isn't situable for situation, where mutiple forms are edited using Django inlines and these related models are meeded for validation.

I usually perfom it in forms (and don't care about the Django admin), but it itn's very food practive. Could you please provide a kind of template service that can be used in such cases?

@timofeiryko Hello 👋

Sorry for the late response.

I'm not sure I understand your question, so I'll say few general things:

  1. You can do validation on top of ORM objects.
  2. You can do validation on raw data (you can safely use forms for this).

If your case is that you are editing a bunch of stuff all at once, perhaps, you need to describe your validation in a function (be it a service) and see how you can pass the data from your forms to that function.

Relying on separate ModelForm validations won't do it in that case, if you need to run validation across a variety of different objects.

If you give me more details / code examples, I think I might provide you with a more helpful answer.

Cheers!

Feel free to reopen this, in case you need additional info 👀