django-trench
django-trench copied to clipboard
phone_number field in different model
I didn't extend AbstractUser model. Instead I've created a Profile model and connected it to User model with a foreign key. How can I use the phone_number field I've created on the Profile model?
With a monkey patch, by adding a phone_number property to the User model.
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="profile")
phone_number = PhoneNumberField()
@property
def get_phone_number(self):
return self.profile.phone_number.__str__()
User.add_to_class("phone_number", get_phone_number)
Hi @ckarli, Does the solution from the above answer work and we can close the issue?
Closing since lack of response for 5 months.