These are chat archives for django/django

31st
Oct 2017
Bernard Parah
@b3h3rkz
Oct 31 2017 01:15 UTC
Hello everyone
please I'll be grateful if someone could take a look at this my SO question
https://stackoverflow.com/questions/46945893/django-restauth-custom-password-reset-link
Justin Weller
@jt-weller
Oct 31 2017 03:29 UTC
Hey all! I'm relatively new to django and the furthest I have gotten is completing the tutorial and looking at videos for said tutorial. I am looking to implement a simple menu on the admin site. Would anyone have any video tutorials on a simple menu? Your help is much appreciated!!!
Anurag Sinha
@anurag03
Oct 31 2017 07:56 UTC
@jt-weller I found this tutorial very helpful for basic learning although it's not in video format as you have asked: https://tutorial.djangogirls.org/en/
Pushplata Ranjan
@pl_b2_twitter
Oct 31 2017 07:56 UTC
@klaxmi361 you can access dictionary with dot operator for eg sample_dict = {'name':"XYZ", "age": 15} in template just write {{sample_dict.name}} will give you XYZ
@b3h3rkz Can you please elaborate more on your question, its not more clear whats the exact issue you are facing
Pushplata Ranjan
@pl_b2_twitter
Oct 31 2017 08:03 UTC
@Wahtdb_twitter Best practice is to do things in backend if it's not depended on user input.
Justin Weller
@jt-weller
Oct 31 2017 15:45 UTC
@anurag03 and @pl_b2_twitter thank you for the help!!
White Rabbit
@Wahtdb_twitter
Oct 31 2017 18:05 UTC
@pl_b2_twitter Do you have an experience with stock price prediction?
Varun
@varunamrutiya
Oct 31 2017 20:17 UTC

Hey all!,
Can I add a permission like 'isStudent' to default django 'User' Model ?

permission = Permission.objects.get(codename='isStudent')
user.user_permissions.add(permission)

Error showing 'Permission matching query does not exist.'

White Rabbit
@Wahtdb_twitter
Oct 31 2017 20:34 UTC
@varunamrutiya why don't you want to add permission decorator to your view or permission_classes = [isStudent]?
Varun
@varunamrutiya
Oct 31 2017 20:35 UTC
@Wahtdb_twitter I didn't get you. U mean define a new permission for the User object ...?

@Wahtdb_twitter I am also trying to do via,

content_type = ContentType.objects.get_for_model(User)
permission = Permission(codename='isStudent',content_type=content_type)
user.user_permissions.add(permission)
user.save()

error 'Cannot add "<Permission: auth | user | >": the value for field "permission" is None'

White Rabbit
@Wahtdb_twitter
Oct 31 2017 20:42 UTC
Sorry, I misunderstood you. Do you want to create for auth_user field isStudent? Something like is set up as default is active etc.?
Dylan Reinhold
@dreinhold
Oct 31 2017 20:42 UTC
pretty sure you just pass the permission name as a string with the model name where you defined the permission
so user.user_permissions.add('my_model.isStudent')
Varun
@varunamrutiya
Oct 31 2017 20:45 UTC
@Wahtdb_twitter Yes I want to add 'isStudent' permission for 'User' object of django auth library. I don't want add a field, but add a permission to 'User' object.
@dreinhold So how to define permission for django auth 'User' Object. It is already imported
Dylan Reinhold
@dreinhold
Oct 31 2017 20:49 UTC
So normally you define them in one of your models, which then you will be able to use in your user object
But you want to define it in in the user model?
If you don't have to, just define it in your "main" model.
class MainModel(models.Model):
   ......
  .......
     class Meta:
         permissions = (
                 'isStudent', 'user is a student',
         )
Varun
@varunamrutiya
Oct 31 2017 20:55 UTC

@dreinhold I was finally able to add permission using

content_type = ContentType.objects.get_for_model(User)
permission = Permission.objects.create(codename='isStudent',name='is student',content_type=content_type)
user.user_permissions.add(permission)
user.save()

but now request.user.has_perm('isStudent') doesn't seem to work. I can see in django/admin that permission object has been added to user.

Dylan Reinhold
@dreinhold
Oct 31 2017 21:01 UTC
it would be 'User.isStudent'
as you defined it in the User model
Varun
@varunamrutiya
Oct 31 2017 21:06 UTC
@dreinhold btw How can you define in User model. It is a part of Djano Auth package, you can only reference it other models.
@dreinhold btw I also tried User.isStudent , it doesn't work.
@dreinhold
Also tried with
permission = Permission.objects.get(codename='isStudent')
    if request.user.has_perm(permission):
Dylan Reinhold
@dreinhold
Oct 31 2017 21:20 UTC
@varunamrutiya Ahh the app_label for User is auth so you need to check for
request.user.has_perm('auth.isStudent')
Varun
@varunamrutiya
Oct 31 2017 21:24 UTC
@dreinhold Yeah it finally worked. Thnx a lot mate.
I read the doc, but didn't realize the argument was <app.name>.<perm> ... was using model name.
Dylan Reinhold
@dreinhold
Oct 31 2017 21:28 UTC
Yeah I though it was Model.Perm also ;)