I want to create some custom validation on models when I do python manage.py runserver
command.
Can I do this somehow?
Asked
Active
Viewed 104 times
0

milandjukic88
- 1,065
- 3
- 13
- 30
-
Why would you do something like that? – finiteautomata Jan 21 '14 at 17:24
-
I'm write some program (with windows) that creates django web app. User can make some logic errors which django cant see. But they will later be revealed while executing django app. – milandjukic88 Jan 21 '14 at 17:28
-
Can you give a thorough example? Not clear enough. – finiteautomata Jan 21 '14 at 17:30
-
for example, I create readOnly field (readOnly is field attribute) without default value and cant be empty. User cannot enter value and while submiting form.... error... (no data) – milandjukic88 Jan 21 '14 at 17:30
-
And why would you choose to do some weird thing as that? Can't you just (from your code) validate this things simply don't happen? – finiteautomata Jan 21 '14 at 17:31
-
Sorry I didnt be clear enough. That program (with windows) is not written by me. My assign is just to create django app from data from that program. Because I'm not sure how they do validation, i want to make another protection. I hope you understand because my english is bad :) – milandjukic88 Jan 21 '14 at 17:35
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/45734/discussion-between-geekazoid-and-milandjukic88) – finiteautomata Jan 21 '14 at 17:37
1 Answers
1
Well, the problem in fact is that you want to run some custom code when your server starts up.
Two possibilities:
- Use
wsgi.py
as suggested by this post. This seems to be the more elegant solution. - Put all your code inside some
__init__.py
file. Be warn that this code will be executed any time you import that package (for example, when you run a django command)

Community
- 1
- 1

finiteautomata
- 3,753
- 4
- 31
- 41