longclawshop/longclaw

'MaxValueValidator' is not defined

fedonkin opened this issue · 8 comments

I do according to the instruction, https://jamesramm.github.io/longclaw/docs/tutorial/products
gives an error:
name 'MaxValueValidator' is not defined
Swears at it:
discount_percent = models.PositiveSmallIntegerField(default=20, validators=[MaxValueValidator(75)])\

I do not understand how to fix :(
heeelp

longclaw version: 1.0.2
Django version: 2.2.6
Python version: 3.7

Check the requirements of the longclaw version you've installed. It will tell which version of Django is supported.

Or provide more code so we can see what your problem is. Did you just copy and paste? You have to import the validator from Django

Or provide more code so we can see what your problem is. Did you just copy and paste? You have to import the validator from Django

Yes, copied and pasted. Is there an example of how to import a validator from django?

This project is an extension of Django and wagtail. To use it effectively you must have good working knowledge of both. I suggest you familiarize yourself with their respective tutorials.

Reference https://docs.djangoproject.com/en/2.2/ref/validators/ for your question about validators

Этот проект является продолжением Django и трясогузки. Чтобы использовать его эффективно, вы должны иметь хорошие рабочие знания обоих. Я предлагаю вам ознакомиться с их соответствующими учебниками.

Ссылка https://docs.djangoproject.com/en/2.2/ref/validators/ на ваш вопрос о валидаторах

Thx!
Is that right?

    def MaxValueValidator(value):
        if value < 75

    discount_percent = models.PositiveSmallIntegerField(
        default=20,
        validators=[
            MaxValueValidator
        ]
    )

Hrm, I cannot understand most of that. English please if possible.

But, the code you provided is incorrect. Django provides the MaxValueValidator out of the box. You just need to import it before you use it... hence the python NameError (https://docs.python.org/2/library/exceptions.html#exceptions.NameError). This isn't a longclaw issue.

from django.core.validators import MaxValueValidator

Hrm, I cannot understand most of that. English please if possible.

But, the code you provided is incorrect. Django provides the MaxValueValidator out of the box. You just need to import it before you use it... hence the python NameError (https://docs.python.org/2/library/exceptions.html#exceptions.NameError). This isn't a longclaw issue.

from django.core.validators import MaxValueValidator

🤗 Oh, thank you very much.

@fedonkin Did this solve your issue? Please close if so - thanks!