Yashwant
age=20, ?
Yeah it's a integer type. Anything wrong?
Yashwant
And also why is this happening?
Yashwant
>>> from signup.models import User
>>> User.objects.all()
<QuerySet []>
Yashwant
Even though I've defined
def __str__(self):
return self.first_name + ' - ' + self.last_name
I'm getting <QuerySet []> instead of First & Last names
Ghazwan
new!!
More like JS, i believe
Anonymous
Oh
Ghazwan
Yashwant
Ghazwan
Yashwant
I'm initializing the class to actually use it
Yashwant
And if I don't use new, I get invalid syntax error
Ghazwan
Ghazwan
Ghazwan
Enter some info to your DB ? do that in your admin page
Yashwant
Yashwant
Ghazwan
Yashwant
That's what I have.
Yashwant
No.
Ghazwan
then ? what is it ?
Ghazwan
custom users model ?
Ghazwan
Why ?
Ghazwan
you don't have to do all that, there is a default user model that is doing that for you.
Yashwant
😂 but the point of my project is to make all the fields
Yashwant
"Personal Profile Management System"
Ghazwan
try using () with those integerfields
Yashwant
Ok.
Ghazwan
Ghazwan
all your class members should have those () actually.
Anonymous
Ghazwan
Yeah every integerfield
Yashwant
Yashwant
Which is weird, it didn't throw any error
Anonymous
number worked
yeah.. it's beacuse it is interprated line by line
Anonymous
number worked
if u swap those two lines of codes, then number would throw error while age wouldn't say anything
Yashwant
Yeah, I get the point now. But for a minute let's not consider number and age...
And I've passed
a = User(first_name="Random", last_name="Person", birth_date=1897-12-17, email="random@xyz.com", profession="Job xyz", hobbies="Working", location="Earth")
as my values. When I call an individual entity/value, say a.first_name() why do I get object not callable? What am I doing wrong?
Anonymous
because first_name is not a function
Anonymous
Anonymous
its a field not a method
Yashwant
Asaduzzaman
I am using weasy for convert html to pdf
Asaduzzaman
but I cant import any fonts or image. How can I do that?
inchidi
inchidi
MyModel.objects.all() return queryset
MyModel.objects.filter() return queryset
MyModel.objects.get() return model object
inchidi
so you are not getting "first _name - last_name" because you are calling queryset and its empty queryset
inchidi
Yashwant
inchidi
can you post the text version of User(...) here so i can easily fix it?
inchidi
oh wait, is this User from django.contrib.auth.models?
Yashwant
No.
inchidi
so its you own User models right?
inchidi
how is you User model class looks like?
Yashwant
Basically, what my project is, is I have to create a Personal Profile Management System, so that a user can fill out those fields and can edit them at any point later on, when it's necessary. All these details are protected by giving the user a username & a password, for modifying & viewing their details.
Yashwant
inchidi
Yashwant
Sure, I'm open to suggestion!
Yashwant
inchidi
replace your User model with this:
class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
birth_date = ...
age = ...
number = ...
profession = ...
hobbies = ...
location = ...``
Yashwant
Yashwant
Ohh ok!
inchidi
when you want to create new user and its profile do this:
>>> from django.contrib.auth.models import User
>>> from yourapp.models import UserProfile
>>> usr= User.objects.create_user(username="test1",password="yourstr0ngP4ss",email="email@email.com",first_name="Yash",last_name="want")
>>> UserProfile.objects.create(user=usr, ...)
inchidi
add
from django.contrib.auth.models import User
on top
inchidi
django User model already have its own email, first_name, last_name fields
inchidi
so you dont need those fields on your UserProfile
Yashwant
So just remove those fields? Ok!
inchidi
yeah, dont forget to makemigrations and migrate
Yashwant
Yep!
Yashwant
inchidi
you dont need import UserProfile, you are creating it there and you have typo in your class name
Anonymous
I think you need to learn python first