Skip to content
Advertisement

Tag: django

Sorting out Django and MySQL in virtualenv

I’m following this tutorial to get started with Django, but I’m very confused about how to integrate MySQL. Doing this in the context of virtualenv (which is new to me) seems to complicate things even further. I’m running on Ubuntu and the MySQL server is on another host. Here are my specific questions: What packages do I need to install

How can I create an encrypted django field that converts data when it’s retrieved from the database?

I have a custom EncryptedCharField, which I want to basically appear as a CharField when interfacing UI, but before storing/retrieving in the DB it encrypts/decrypts it. The custom fields documentation says to: add __metaclass__ = models.SubfieldBase override to_python to convert the data from it’s raw storage into the desired format override get_prep_value to convert the value before storing ot the

How to check if the object has property in view in Django?

I am trying to get the documents property in a general function, but a few models may not have the documents attribute. Is there any way to first check if a model has the documents property, and then conditionally run code? Answer You can use hasattr() to check to see if model has the documents property. However, this answer points

How to add column in ManyToMany Table (Django)

From the example of Django Book, I understand if I create models as following: The Django would create a new table(A_B) beyond Table A, which has three columns: id a_id b_id But now I want to add a new column in the Table A_B, thus would be very easy if I use normal SQL, but now anyone can help me

Determine if Django is running under the development server

Is there a way to determine if Django is running on localhost and setting the DEBUG variable in settings.py accordingly. So that if I run the server locally it will set DEBUG to True and otherwise set it to False. Localhost: python manage.py runserver Not localhost: python manage.py runserver 0.0.0.0:8000 Answer As suggested by Bernhard Vallant, you can just check

Django:any way to remove this clear field?

Is there any way I can remove this model form file field’s ‘clear’ checkbox?.I know that I can define the ‘custom’ widget for file field but how to address this checkbox in that? Answer You need to change the widget from the ClearableFileInput to Fileinput https://docs.djangoproject.com/en/dev/ref/forms/widgets/#fileinput

Nothing happens when I do: python manage.py command

I’m new to django and currently going through the main tutorial. Even though it was working earlier, when I do python manage.py runserver OR python manage.py -h OR with any other command, the shell doesn’t output anything. Wondering what I’m doing wrong. Answer First, check if python is fully installed by typing “python” in a shell. Then you should try

Advertisement