I am building a user model and wanna attach it to a modelform as below shown. How can I get the email of each user by shell accessing the mysql database?
I have tried these to get the data by shell, but the previous one said the object has no email attribute and the latter one said the forms.py has no object.
from Project.User.models import UserProfile as p
p.objects.filter(is_active=True).first().email //
from Project.User.forms import ClientProfileForm as p
p.objects.filter(is_active=True).first().email
Code:
models.py:
class UserProfile(BaseModel):
user = models.OneToOneField(User, primary_key=True, on_delete=models.CASCADE, verbose_name='client')
name = models.CharField('name',max_length=30, null=False, help_text="Name")
gender = models.CharField('sex',max_length=1, help_text="Sex")
class Meta:
verbose_name = 'Client'
verbose_name_plural = 'Client'
def __str__(self):
return 'client:%s' % self.user
forms.py:
class ClientProfileForm(forms.ModelForm):
email = forms.EmailField()
class Meta:
model = UserProfile
fields = ("user", "name", "gender")