[Answered ]-How to prepopulate UserProfile fields in the Django admin?

2👍

slug is a field in UserProfile, but the prepopulated_fields = {"slug": ("name",)} is an attribute of UserProfileAdmin, which is applied to User.

prepopulated_fields triggers some javascript that autogenerates the value of a SlugField out of the values of some other fields of the same model. What you are trying is to prepopulate a field of a different model. The UserProfileAdmin is applied to User, the prepopulated_fields refers to the field slug which is unknown to the model User. It is defined in UserProfile.

That’s why I think that the biggest problem here is the name UserProfileAdmin which should rather be UserAdmin. Don’t confuse the model to which the prepopulated_fields is applied with the one that is inlined. Even when there is a OneToOne relation, it still is a different model.

👤jammon

Leave a comment