Nats
May be you data has some problem about json serializable
Rabi Subedi
is it better to mix user and admin for same endpoints
Nats
such has np.bool, you shoud use bool instead of np.bool
Najim patel
remove : before typecasting
if components["port"]: components["port"] = int(components["port"]) can you plz edit here
....
how to show all likes count in each post - django REST API https://dpaste.org/OwNd = check this code . post 1 have 2 likes post 2 have 1 like post 3 don't have any like i want to show this like this . but it's showing the first post likes for every post . how can i fix this .? i know the problem in the like_count in view . but i don't know what to put there instead of id . how to fix this . ?
Arslan
why do you need like field in postlike model?
....
why do you need like field in postlike model?
is it not a good idea . ? the post should have lot of likes . so in this case .
Arslan
You can leave two foreignkeys user and post
Arslan
but you have to give them related names
....
is it not a good idea . ? the post should have lot of likes . so in this case .
also when i did likes = models.ManyToManyField(User, related_name='likes',) like this , it's not showing in database
Alex
how to show all likes count in each post - django REST API https://dpaste.org/OwNd = check this code . post 1 have 2 likes post 2 have 1 like post 3 don't have any like i want to show this like this . but it's showing the first post likes for every post . how can i fix this .? i know the problem in the like_count in view . but i don't know what to put there instead of id . how to fix this . ?
1 Don't nest models. I code django for 6 years and it's literally the first time I see someone to do this. 2 To count - something like Post.objects.all().annotate(likes=Count('postlike')) https://docs.djangoproject.com/en/4.0/topics/db/aggregation/ 3 In your serializer likes = serializers.IntegerField(source='likes')
Kaustubh
I want to add the field of a model to another model , how can I do that
Alex
I want to add the field of a model to another model , how can I do that
For example your can copypast it. Or, if there is a logical relation between them, you can inherit one from another.
Kaustubh
its better to write separate models
I want to add phone field of a model to another model and secondly I want to display the data of phone model on frontend
Fan / Ac
YESS
inheritance wont help you, search django model relationships, its a sql concept https://docs.djangoproject.com/en/4.0/topics/db/examples/
Kaustubh
Show us what you have already done.
Okay Sir wait I will show you photos
Fan / Ac
Can you please tell me the code for it that can I write in models.py
i am still not exactly sure if this is what you need, so read about django model inheritance and relationships between models in django and use what you need
Alex
Okay Sir wait I will show you photos
No, no photos. Post on pastebin
Kaustubh
class extendeduser(models.Model): phone=models.CharField(max_length=12) cat=models.CharField(max_length=10) town=models.CharField(max_length=50) user=models.OneToOneField(User,on_delete=models.CASCADE) def str(self): return str(self.user)
Kaustubh
class WillPlant(models.Model): user=models.CharField(max_length=20) crop=models.CharField(max_length=20) town=models.CharField(max_length=20) def str(self): return self.town
Kaustubh
I want to use that phone field in willplant model
Alex
Then you can do it like will_plant = WillPlant.objects.get(id=1) will_plant.user.phone And after that read about select_related
Me
Sorry guys, am using Django 4.0 amd whenever I want to view admin site it gives me ZoneInfoNotFound error. Can somebody help me please!
Alex
Where should I write this code?
In your project, where you consider it to be.🤷‍♂️
Alex
Can I just copy paste the phone code in willplant model
Well, you can, but I would name it a stupid decision. You will have to control the consistency of your data which is actually the job your DB probably does fine.
Alex
But again, go ahead.
Thuy
thanks
Parithi
Hey does anybody knows how to validate username and password separately in django ????
ShuvamTheBeast
Can i Learn django without html css?
Alex
Can i Learn django without html css?
Sure. You can just write API backend for someone.
Sukuna
Which is better for better performance for a Ecommerce website django or drf?
cj
Which is better for better performance for a Ecommerce website django or drf?
for e-commerce maybe you'd want to take a look to Odoo instead of Django... but talking only about django, it depends on how you write your code, not if you use drf or not ¯\_(ツ)_/¯
Alex
Which is better for better performance for a Ecommerce website django or drf?
I've said - just do your job with the tools you're best familiar.
Sukuna
Thanks
M@hs@
Hi everyone I have a rigid problem on my server When i change debug to false, all static files like images, css, js files separately on browser is shown correctly But the entire theme not loaded correctly I have checked settings.py and nginx config multiple times, but i dont know what'a the problem Thanks a lot for your help🙏🙏🙏
V-taggie
Can i Learn django without html css?
Yes 100% you will be developing api so that front-end parties can consume
V-taggie
Which is better for better performance for a Ecommerce website django or drf?
If you are are planning to just create a website pertaining e-commerce you can write it just with django but if you want your app to be consumed by different front-end tools like React, flutter etc then drf is the way to go and its the most good way to go to my view
Carsalberto
STATIC_ROOT
M@hs@
I set this path
Carsalberto
document_root=settings.STATIC_ROOT
M@hs@
I have image path inside css files like this ../img/grid.png
M@hs@
Set this line into urls.py when debug is false
Y
Hello guys. I have downloaded Django project,so I would like run this project. When I execute python3 manage.py runserver ,I have ModuleNotFoundError
Y
This error is no Module named 'psycopg2'
Y
Please someone's can I help me?
Y
*can you?
toygar
This error is no Module named 'psycopg2'
google it. The first site has the answer.
M@hs@
This error is no Module named 'psycopg2'
Pip install psycopg2-binary Please test this library
M@hs@
Ok thanks you
🙋‍♀
Y
make sure to install the dependencies
I have install dependencies but I have always ModuleNotFoundError
Y
Pip install psycopg2-binary Please test this library
Despite psycopg2 installation, I have same error
M@hs@
Despite psycopg2 installation, I have same error
Check this Sudo apt install libpq-dev python3-dev After that run previous command again
Machan
Python3.8.8 Django 4.0.1 Pls step to django app creation
Doragonsureiyā
Python3.8.8 Django 4.0.1 Pls step to django app creation
Looking for Django tutorials? you can follow these three recommended ones: * Official documentation and tutorial * Tutorial from MDN * Tutorial from django-girls
Machan
Thanks
ShuvamTheBeast