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
I'm trying to enter them, but getting that indent error
As Sinatra said, where did this new come from ?
Yashwant
I'm initializing the class to actually use it
Yashwant
And if I don't use new, I get invalid syntax error
Ghazwan
And if I don't use new, I get invalid syntax error
What are you trying to do anyway ?
Ghazwan
Enter some info to your DB ? do that in your admin page
Yashwant
What are you trying to do anyway ?
I'm just trying to check if DB is taking any info/entries
Ghazwan
I'm just trying to check if DB is taking any info/entries
python manage.py createsuperuser >>> enter valid information python manage.py migrate python manage.py makemigrations go to your local_host/admin
Yashwant
python manage.py createsuperuser >>> enter valid information python manage.py migrate python manage.py makemigrations go to your local_host/admin
But what's the point of this? I'm trying to add a person's profile into my system. This is more like adding users to the administration :/
Yashwant
That's what I have.
Ghazwan
No, open the admin page and you will know it all.
also if you do want to quickly test your DB, use fake library in order to populate it.
Ghazwan
That's what I have.
it is user model, isn't it ?
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.
Yashwant
try using () with those integerfields
Ok, so there's something wrong with age. How should I define it?
Ghazwan
all your class members should have those () actually.
Ghazwan
Yeah every integerfield
Yashwant
Which is weird, it didn't throw any error
Ghazwan
Which is weird, it didn't throw any error
that is python, it never throw an error before the line is executed unlike compiled languages.
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
its a field not a method
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
Even though I've defined def __str__(self): return self.first_name + ' - ' + self.last_name I'm getting <QuerySet []> instead of First & Last names
there's two different things in django, queryset and model object. when you override magic method __str__, thats means you will get returned value when you call the model object as string
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
Group Butler
thats gonna be a lot and harder work than create new django models. but first step to do one of them you still need understanding about django models
New to Django? here is some resource to start Official docs tutorial Step by step tutorial Video tutorial Another video tutorial Books Django by Example Tango With Django
inchidi
can you post the text version of User(...) here so i can easily fix it?
Yashwant
can you post the text version of User(...) here so i can easily fix it?
a = User(first_name="Random", last_name="Person", birth_date=1897-12-17, age=20, email="random@xyz.com", profession="Job xyz", number=1234567890, hobbies="Working", location="Earth")
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
Sure, I'm open to suggestion!
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 = ...``
inchidi
So that, if I delete any entity the entire user will be removed, correct?
not entire user, if you delete one User, its UserProfile gonna be deleted too
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!
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