Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to you monkey patch the Django user model?

I want to monkey patch the user model from Django.

My code:

from django.db import models

from django.contrib.auth.models import User
User.add_to_class('secret_question', models.CharField(max_length="100"))
User.add_to_class('answer', models.CharField(max_length="100"))
User.add_to_class('DOB', models.DateField())

Where do I place this code so that python manage.py syncdb will create the correct table?

I tried the main directory models.py, I tried an app's directory's models.py (these two didn't produce the correct table), and I tried placing it in the settings.py of the project (error, couldn't run).

like image 580
Derek Avatar asked Dec 30 '25 02:12

Derek


1 Answers

Please take a look at Storing additional information about users section of the authentication documentation. It suggests a cleaner way to add additional information to a User object.

If you'd like to store additional information related to your users, Django provides a method to specify a site-specific related model -- termed a "user profile" -- for this purpose.

like image 98
miku Avatar answered Dec 31 '25 14:12

miku



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!