M
Oh let me check it more . thanks
Pradyum
How to add users in group?
Pradyum
I have created a group and given appropriate permissions to i
Pradyum
but am not able to add users to that group
Pradyum
Example >>> admin <Group: group_admin> Now adding user to the group example text >>> admin.user.add(test) Traceback (most recent call last): File "<console>", line 1, in <module> AttributeError: 'Group' object has no attribute 'user'
Sadra
Example >>> admin <Group: group_admin> Now adding user to the group example text >>> admin.user.add(test) Traceback (most recent call last): File "<console>", line 1, in <module> AttributeError: 'Group' object has no attribute 'user'
>>> from django.contrib.auth.models import User, Group >>> my_group = Group.objects.get(name='groupname') >>> my_users = User.objects.filter(<your_filter>) >>> for my_user in my_users: ... my_group.user_set.add(my_user)
Sadra
This shall also work with a custom user model?
Looks. Not pretty sure.🙊😅 If you've inherited your model with the BaseGroup model, there will be no issue. Mostly, managers add users using the user interface.
Pradyum
Yes, have inherited AbstractBaseUser and BaseUserManager I asked because issue persist
Pradyum
>>> mygroup <Group: group_admin> >>> User.objects.filter(id=user_id).get() <User: agency@user.com> >>> my_user = User.objects.filter(id=user_id).get() >>> mygroup.user_set.add(my_user) Traceback (most recent call last): File "<console>", line 1, in <module> AttributeError: 'Group' object has no attribute 'user_set'
Sadra
hold on.
Sadra
Did you create a new Group inherited from django.contrib.auth.models.Group or it's the exact model?
Pradyum
yes absolutely
Pradyum
and even am also able yo list down all the groups and their respective permissions Group.objects.all()
Pradyum
to*
Anonymous
Can anyone help me that how can i get job .i am fresher and i know python, django,css,html MySQL
Pradyum
Did you create a new Group inherited from django.contrib.auth.models.Group or it's the exact model?
Could I provide you any extra information on this to solve this issue?
Sadra
Can anyone help me that how can i get job .i am fresher and i know python, django,css,html MySQL
I don't know if I'm allowed to send such a link but this might help you. https://www.pythonjobshq.com/
Sadra
and even am also able yo list down all the groups and their respective permissions Group.objects.all()
Please wait a sec. I'm working on it. Text you once caught the solution. :))
Pradyum
Okay no issues, Thank you for taking out time on this :)
Pradyum
Yes, have inherited AbstractBaseUser and BaseUserManager I asked because issue persist
Okay I found the error @lnxpy I have to add https://stackoverflow.com/a/36961259/7999665 PermissionsMixin too in AbstractBaseUser
Pradyum
and then makemigrations add the groups for the custom user model
Pradyum
That was the reason it was not working makemigrations gave this result> - Add field groups to user - Add field user_permissions to user
R.U.S.H.A.B.H
Typeerror :- 'ManyRelatedManager' object is not iterable Error coming while printing the many to many field in html template
Anonymous
Do any one have hands on how to use docker in windows 10 home using virtual box
Doragonsureiyā
Do any one have hands on how to use docker in windows 10 home using virtual box
Looks like you need an offtopic group, please continue this conversation at @pythonofftopic as it's not related to Python
R.U.S.H.A.B.H
R.U.S.H.A.B.H
😌
Anonymous
Is it possible to add a widget or any option on admin for ImageField so that if the image already exists in my S3 bucket we just put the URL for the same. Do I have to change something in models or have to override save method? If anyone knows a approach please help.
Anonymous
Yea. you can override the save method.
Do you mean adding 2 fields in models and then overriding save method for checking the fields? Am I right?
Darth✧
I m facing some difficulty while connecting ec2 and pycharm as remote host for my django project ....can anyone help ?
Sunder
I am unable to start the server in windows 7.
Sadra
Do you mean adding 2 fields in models and then overriding save method for checking the fields? Am I right?
Does not belong to views. You just override the save mathod on models. https://stackoverflow.com/questions/4269605/django-override-save-for-model
Sadra
You can make a condition in the save method and check if any object with the same value is existing. If the condition turns True, you need to raise a proper exception.
Anonymous
Hello, how do you document you Django rest framework(DRF) APIs, using swagger or something else, I am just exploring a solution which requires the least effort, postman is good but its has its limitations mostly related to pricing
Rockefeller
Hey guys!!
Shyamkumar
how share code !
tricky_Velvet
please share your code dum dum
tricky_Velvet
Dude use a service ..
Sai
Can i see your code
Armin
She/He means use a code sharing service like bitbucket and share the link
Rids
I need to make a chatting app in Django..where should I learn
Rids
Someone please help
Sadra
I need to make a chatting app in Django..where should I learn
Start with Django Channels. The first app you create is about chatting in separated rooms.
Rids
I don't know about django channels
Rids
What is it
Rids
Can you tell me more
Sadra
Creating an isolated environment which transfers all packets and data asynchronously. Google knows better. :) ❤️
Rids
What are web sockets
Sadra
What are web sockets
Web Socket is a transfer protocol that is based on Django Channels.
Rids
Ok thank you so much
Sadra
Ok thank you so much
:) ❤️ Good luck.
Sunder
what is the error??
Python is not recognize as an internal or external command
Sunder
I am new and just started learning
Sunder
Python is not recognize as an internal or external command
os- windows 7(32 bit) path of python- C:\Users\pc\AppData\Local\Programs\Python\Python38-32 C:\Users\pc\AppData\Local\Programs\Python\Python38-32 C:\Users\pc\AppData\Local\Programs\Python\Python38-32>python -m django --version 3.1.2 C:\Users\pc\AppData\Local\Programs\Python\Python38-32>python --version Python 3.8.6 in VS terminal C:\Users\pc\Desktop\VSC\hello>python manage.py runserver 'python' is not recognized as an internal or external command, operable program or batch file.
Mapesa 🗽
Just want to know which is better kivy or django ???
cj
Just want to know which is better kivy or django ???
you can't compare them, they are not related on any way, it's like wanting to compare an apple with a cat
Sunder
After installing python,👆is the path
Chyngyz
Hey everyone. Do you know how to add fields to model based on Boolean field? For example, i need to add fieldA if status=True, else add fieldB
Omair
Hey everyone. Do you know how to add fields to model based on Boolean field? For example, i need to add fieldA if status=True, else add fieldB
You could use django signals to trigger something if the boolean field is changed but IMO adding a model field on the fly would not be the way to go forward.
Omair
Hey everyone. Do you know how to add fields to model based on Boolean field? For example, i need to add fieldA if status=True, else add fieldB
You should have both the fields pre-defined in your model and use the django signal to update the value in those fields
Omair
Or if you are using Postgresql as the database you could use a json field to store a key value pair depending on the boolean
DTN
Hi. I have made a django modelform that i pass to my ModelAdmin but it renders like in the second picture. How can I get my fields to get render like in the first picture? https://imgur.com/a/E4KYZkS
Ayomide
i have an issue with handling staticfiles in production server.... the staticfiles arent coming through with nginx and gunicorn
Ayomide
any suggestions please ?