Source

django-python-code-field /

Python Source Code Field

If you need to store python source code in a field in a django model, this
is the app you need.

Obviously, you should not be accepting any old user data if you will be
executing it, but for my use case (admin users only, needed complex data
rules that varied between models), python code was the best choice.

So, you use it by:

$ python setup.py install

add python_field to your settings.INSTALLED_APPS (optional, but
required if you want syntax highlighting).