Name error

2019-06-05 Thread RAJA MISHRA
Name error : name 'django' is not defined in one of my app
Plzz anyone explain how to fix this
 also how to use django.setup()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4bbd7afe-ddd8-4c25-a620-7e6da5ddd5c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Name error

2019-06-05 Thread Sipum Mishra
Plz show your code otherwise search your total error line in Google you can
find it.
Always try to paste error codes so that it will b easy to find out error.

Thanks.

On Wed, 5 Jun, 2019, 3:12 PM RAJA MISHRA, 
wrote:

> Name error : name 'django' is not defined in one of my app
> Plzz anyone explain how to fix this
>  also how to use django.setup()
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4bbd7afe-ddd8-4c25-a620-7e6da5ddd5c5%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGHZBzzo8Ks05zFq7eVHjGFQV1aF5E5D%2B7zMe1cH%3D2PAUwN6Vg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: What's the best way to inherit boolean values from a model?

2019-06-05 Thread Chetan Ganji
No need for inherit permissions.  As it will increase one more if condition
to be checked.
But, whenever a new user is created, you have to read the values from its
companys permissions and set them for the current user.
If companies permissions are updated, all of its employees permissions
needs to be updated as well.

This is a typical example of a Nested CRUD.



class BasePermissions(models.Model):
allow_blog_access = models.BooleanField(default=True)
allow_shop_access = models.BooleanField(default=True)
allow_admin_access = models.BooleanField(default=True)

class Meta:
abstract = True


class Company(BasePermissions):
name = models.CharField(max_length=255)


class CustomUser(BasePermissions, AbstractUser):
company = models.ForeignKey(Company, on_delete=models.CASCADE, related_name=
"customuser")



Cheers!


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Jun 5, 2019 at 4:26 AM Tal  wrote:

> Lets say I have 2 models:
>
>
> class Company(models.Model):
>  name = models.CharField(...)
>  allow_blog_access = models.BooleanField(...)
>  allow_shop_access = models.BooleanField(...)
>  allow_admin_access = models.BooleanField(...)
>
>
> class User(AbstractUser):
>  company = models.ForeignKey(Company, ...)
>  ...
>
>
>
> Here, users can be assigned to a company, and when a user tries to access
> a particular webpage,
> the view can check:
>
>- Does this user's company have access to this area (ex. the blog app)?
>
>
> This is great. That means access to particular areas (or apps) of the site
> can be controlled at the company level.
> When you create a user, you just assign him to a company, and whatever the
> company is allowed to access, he is
> as well. It makes updating access a lot easier too, when you can change it
> in one place (at the company level), instead
> of doing it for every user.
>
> The problem I'm having is that one or two users that are part of a
> particular company need access to most of, but
> not all of, the areas the company has access to.
>
> What's the best way to implement this?
>
> The main thing I can think of is to have the User class also have Boolean
> fields for allow_blog_access, allow_shop_access
> and allow_admin_access, but add another field called inherit_permissions
> (also boolean). It would look like this:
>
>
> class Company(models.Model):
>  name = models.CharField(...)
>  allow_blog_access = models.BooleanField(...)
>  allow_shop_access = models.BooleanField(...)
>  allow_admin_access = models.BooleanField(...)
>
>
> class User(AbstractUser):
>  company = models.ForeignKey(Company, ...)
>  allow_blog_access = models.BooleanField(...)
>  allow_shop_access = models.BooleanField(...)
>  allow_admin_access = models.BooleanField(...)
>  inherit_permission = models.BooleanField(...)
>  ...
>
>
>
> If inherit_permissions for a user is set, the view should look at the
> permissions of the company the user belongs to
> (request.user.company.allow_blog_access).
> If inherit_permissions for a user is not set, the view should look at the
> permissions of the user (request.user.allow_blog_access).
>
> Is there a better way to do this? Or is that the simplest?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c0051d28-de5d-427f-87da-4bd986734f69%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMKMUjvPk-%2BYqrZyG0NxvBsMCyLWOfds2QnbVF7MaPv_4H0Y_g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Name error

2019-06-05 Thread Raichand Ray
6bbb6b5b655b5556555tgt

On Wed 5 Jun, 2019, 3:17 PM Sipum Mishra,  wrote:

> Plz show your code otherwise search your total error line in Google you
> can find it.
> Always try to paste error codes so that it will b easy to find out error.
>
> Thanks.
>
> On Wed, 5 Jun, 2019, 3:12 PM RAJA MISHRA, 
> wrote:
>
>> Name error : name 'django' is not defined in one of my app
>> Plzz anyone explain how to fix this
>>  also how to use django.setup()
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/4bbd7afe-ddd8-4c25-a620-7e6da5ddd5c5%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGHZBzzo8Ks05zFq7eVHjGFQV1aF5E5D%2B7zMe1cH%3D2PAUwN6Vg%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGQNQsW7ak%2BD13MTuuML6%2BBLsB-6%2BmdDm%3DOoi4WmRYVyJM1Qkg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to migrate MySQL -> PostgreSQL?

2019-06-05 Thread Devender Kumar
Hi,
*It's very complicated with not much explanation in question.*
Its depend on where you want to do this process Development or Production.
If it is development then and not holding a very large amount of data.
then its not very complicated
 dump JSON > change database engine > load JSON.
If its production end then you might have to write some scripts to copy
data from one database (MySQL) to dump Into another database (PostgreSQL)
in between you can use transition state of JSON OR XML

Thank you


On Tue, Jun 4, 2019 at 2:46 PM Julien Enselme <
julien.ense...@bureauxlocaux.com> wrote:

> Hi,
>
> At my company we recently made a switch from MySQL to PG. We used
> https://pgloader.io/ to load the data from MySQL to PG. It reliable and
> quite fast (we had about 2GO of data to migrate in multiple table). The
> tool will handle table creation and data migration. As @Kiran said, try
> first in a test env. It may take a while depending on the amount of code
> that relies on MySQL specific features. I hope this helps!
>
> Regard,
> Julien Enselme
> Développeur chez BureauxLocaux
>
>
> Le mar. 4 juin 2019 à 00:56, Kiran Capoor  a
> écrit :
>
>> Hi,
>>
>> As said by ankhi, change to pgsql in settings before that use the django
>> fixtures feature to take a backup of the data etc. try in test env only as
>> this has breaking potential.
>>
>> Regards,
>> Kiran Capoor
>>
>> On Tue, 4 Jun 2019 at 01:33, Ankhi Roy  wrote:
>>
>>> Hey Victor,
>>>
>>> Do you mean to use postgresql instead of mysql,  if so please change
>>> database settings in settings.py. However,  I am not sure how will you
>>> migrate your existing mysql tables and contents to postgresql. Just a
>>> workaround you can recreate tables in postgresql and re add the data. There
>>> must be an efficient way though.
>>>
>>> Thanks
>>> Ankhi
>>>
>>> On Mon, Jun 3, 2019, 8:21 PM Victor Porton  wrote:
>>>
 How to migrate a production database MySQL -> PostgreSQL?

 (MySQL has several bugs, I want to try something other on my production
 server.)

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users+unsubscr...@googlegroups.com.
 To post to this group, send email to django-users@googlegroups.com.
 Visit this group at https://groups.google.com/group/django-users.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/97a3c018-86ee-462a-a21a-6d2a7971adc1%40googlegroups.com
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CABUQWg_hm7U__cwKJvFvvvR3osuz-MtswCL1YLA74pGdEvp_PA%40mail.gmail.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> Sent from iPhone
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAANvM2%3DHjGDSL3_rX6adnkp-8o%2Bj9trx9as0AMC5VGpMw25nZA%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAL%3D_h26ttWeRZ5cv4dADrmLg4upJC65zdg4%3Dw1GFc8qZLUU5nw%40mail.gmail.com
> 

Re: Error is MultiValueDictKeyError at /login

2019-06-05 Thread Anirudh Jain
In login function, could you try password =request.POST['password1']

You have used ['password']

On Wed, 5 Jun 2019, 17:22 sahukara harish, 
wrote:

> Hi, to all can any one help me to rectify this error
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJTXQ2OAq6GuXQDfiqwRELc26p1nWaPP%2Bvqv9j7T35JJH2DcgQ%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAC3mK7fnb2Mi4kpccffwWPR3ThuQUxJ9iHUxrZxP0kLw_sZo8w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: While registering the user with django form, it gives "UNIQUE constraint failed: auth_user.username" error

2019-06-05 Thread Joe Reitman
The problem with Jaydeep's code is the 'username' field is not getting 
populated in the auth_user table. Django auth_user table by default must 
have unique usernames. Username is what Django authenticates to by default. 

Jaydeep was able to enter the initial user with email, firstname and 
lastname once because he left 'username' field blank. The second time 
failed because there is already a blank 'username' causing it to throw the 
Unique Constraint error. 

Also, as this code is written the 'userprofileinfo' table is not getting 
populated with any data.



On Tuesday, June 4, 2019 at 8:24:30 AM UTC-5, Flexian_me wrote:
>
> Consider we want another attribute in user model other than what is 
> already available, for example height or weight. Still this code is giving 
> error and focus should be to solve the issue that OP is facing. I am also 
> facing same issue and trying to figure it out.
> @Jaydeep Did you get to solve the issue somehow?
>
> Thanks!
>
> On Saturday, 18 May 2019 04:01:56 UTC+5:30, Joe Reitman wrote:
>>
>> I'm not sure what your objective is but you don't need to create another 
>> model to store user data. User data is stored in the auth.models. It has 
>> fields already available for what your trying to accomplish. 
>>
>> On Saturday, October 6, 2018 at 8:28:09 AM UTC-5, Jaydeep Borkar wrote:
>>>
>>> When I try to register a user using Django form, it gives me "UNIQUE 
>>> constraint failed: auth_user.username". When I tried registering the first 
>>> user, it worked, but I couldn't see that entry in my database. When I tried 
>>> registering the second user, it's giving me this error. Please, help me 
>>> through this. I have spent a considerable amount of time on this and I'm 
>>> stuck. 
>>>
>>> This is my code: 
>>>
>>> forms.py 
>>> from django import forms
>>> from django.contrib.auth.models import User
>>> from volunteer.models import UserProfileInfo
>>>
>>> class UserForm(forms.ModelForm):
>>>
>>> class Meta():
>>> model = User
>>> fields = ('email','first_name','last_name')
>>>
>>>
>>>
>>>
>>> views.py 
>>> from django.shortcuts import render
>>> from volunteer.forms import UserForm
>>>
>>>  
>>>
>>> def register(request):
>>>
>>> registered = False
>>>
>>> if request.method =="POST" :
>>> user_form = UserForm(data=request.POST)
>>>
>>> if user_form.is_valid():
>>>
>>> user = user_form.save()
>>> user.save()
>>>
>>> registered = True
>>>
>>> else:
>>> print(user_form.errors)
>>>
>>> else:
>>> user_form = UserForm()
>>>
>>> return render(request, 'volunteer/volunteer.html',
>>>  {'user_form':user_form,
>>>   'registered':registered})
>>>
>>>  
>>>   
>>>
>>>
>>> 
>>>
>>>
>>>
>>> models.py 
>>> from django.db import models
>>> from django.contrib.auth.models import User
>>>
>>> class UserProfileInfo(models.Model):
>>>
>>> user=models.OneToOneField(User)
>>>
>>> def __str__(self):
>>> return self.user.first_name
>>> return self.user.last_name
>>> return self.user.email
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> urls.py
>>> from django.conf.urls import url
>>>
>>> from . import views
>>>
>>> app_name = 'volunteer'
>>>
>>> urlpatterns = [
>>>
>>>  url(r'^', views.register, name='register'),
>>> ]
>>>
>>>
>>>
>>> admin.py
>>> from django.contrib import admin
>>> from volunteer.models import UserProfileInfo
>>>
>>> # Register your models here.
>>> admin.site.register(UserProfileInfo)
>>>
>>>
>>>
>>> volunteer.html file which has the user form
>>> 
>>> 
>>> 
>>> 
>>>  
>>>  
>>> 
>>>
>>>  
>>> https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css";>
>>> https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
>>> ">
>>> https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js
>>> ">
>>>  https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js
>>> ">
>>>  
>>>   
>>>  
>>>   
>>>
>>>  
>>> {% if registered %}
>>>Thanks!
>>> {% else %}
>>>   Register
>>>
>>>
>>>  
>>> {% csrf_token %}
>>> {{ user_form.as_p }}
>>>  
>>>
>>>  {% endif %}
>>>
>>>   
>>>
>>>  
>>>  
>>>
>>> 
>>>  
>>>
>>>
>>>
>>> I feel there's some problem in views.py or models.py, or volunteer.html. 
>>> or maybe something else. Please, guide me through this. 
>>> Thanks in advance. 
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e93025c7-5d4b-4ed8-83fa-f189232

Django user profile shared among different apps

2019-06-05 Thread Gaurav Sahu
Hy Everyone,
I have a Django website which has multiple apps one of the apps is accounts 
app. accounts app is responsible for user sign up and authentication. Now I 
want to create a user profile in my website and that user will be the same 
across all of my web apps. how can I implement this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/85bdf45d-ed9e-4a85-a9ce-df25e8b9e2c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Existing database for users to use django user auths

2019-06-05 Thread michael ababao
I am new to django and i would like to know if it is possible to use the django 
user authentication using a different database for users?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/688efd6f-8768-44e0-b9aa-79e6b508bfb4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: While registering the user with django form, it gives "UNIQUE constraint failed: auth_user.username" error

2019-06-05 Thread Chandrashekhar Singh
Better will be, delete all migrations, and again migrate

On Fri, May 17, 2019, 12:51 PM RAJENDRA MYTHILI 17BIS0120 <
rajendra.mythili2...@vitstudent.ac.in> wrote:

> I'm facing the same issue ... Did you figure out what's wrong?
>
> On Saturday, October 6, 2018 at 6:28:09 AM UTC-7, Jaydeep Borkar wrote:
>>
>> When I try to register a user using Django form, it gives me "UNIQUE
>> constraint failed: auth_user.username". When I tried registering the first
>> user, it worked, but I couldn't see that entry in my database. When I tried
>> registering the second user, it's giving me this error. Please, help me
>> through this. I have spent a considerable amount of time on this and I'm
>> stuck.
>>
>> This is my code:
>>
>> forms.py
>> from django import forms
>> from django.contrib.auth.models import User
>> from volunteer.models import UserProfileInfo
>>
>> class UserForm(forms.ModelForm):
>>
>> class Meta():
>> model = User
>> fields = ('email','first_name','last_name')
>>
>>
>>
>>
>> views.py
>> from django.shortcuts import render
>> from volunteer.forms import UserForm
>>
>>
>>
>> def register(request):
>>
>> registered = False
>>
>> if request.method =="POST" :
>> user_form = UserForm(data=request.POST)
>>
>> if user_form.is_valid():
>>
>> user = user_form.save()
>> user.save()
>>
>> registered = True
>>
>> else:
>> print(user_form.errors)
>>
>> else:
>> user_form = UserForm()
>>
>> return render(request, 'volunteer/volunteer.html',
>>  {'user_form':user_form,
>>   'registered':registered})
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> models.py
>> from django.db import models
>> from django.contrib.auth.models import User
>>
>> class UserProfileInfo(models.Model):
>>
>> user=models.OneToOneField(User)
>>
>> def __str__(self):
>> return self.user.first_name
>> return self.user.last_name
>> return self.user.email
>>
>>
>>
>>
>>
>>
>>
>> urls.py
>> from django.conf.urls import url
>>
>> from . import views
>>
>> app_name = 'volunteer'
>>
>> urlpatterns = [
>>
>>  url(r'^', views.register, name='register'),
>> ]
>>
>>
>>
>> admin.py
>> from django.contrib import admin
>> from volunteer.models import UserProfileInfo
>>
>> # Register your models here.
>> admin.site.register(UserProfileInfo)
>>
>>
>>
>> volunteer.html file which has the user form
>> 
>> 
>> 
>> 
>>
>>
>> 
>>
>>
>> https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css";>
>> https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
>> ">
>> https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js
>> ">
>>  https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js
>> ">
>>
>> 
>>
>> 
>>
>>  
>> {% if registered %}
>>Thanks!
>> {% else %}
>>   Register
>>
>>
>>  
>> {% csrf_token %}
>> {{ user_form.as_p }}
>>  
>>
>>  {% endif %}
>>
>>  
>>
>>
>>  
>>
>> 
>> 
>>
>>
>>
>> I feel there's some problem in views.py or models.py, or volunteer.html.
>> or maybe something else. Please, guide me through this.
>> Thanks in advance.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c59e6938-86fd-4cfc-90ed-3053032b8e2d%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADNvQ1OkbZvJNeej3nVzKdt0UnyUSG2ts%3DvirLc1Y-VVbq9c5w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: While registering the user with django form, it gives "UNIQUE constraint failed: auth_user.username" error

2019-06-05 Thread Chetan Ganji
I wrote a python script to easily reset a django project. I hope it helps
you.
Just put it in the folder where manage.py file is and run it.


import os
import shutil

from pprint import pprint


folders = []
base_dir = os.path.dirname(os.path.realpath(__file__))


def get_directory_list():
global folders
global base_dir

for root, d_names, f_names in os.walk(base_dir):
for name in d_names:
folders.append(os.path.join(root, name))
folders = sorted(folders)
return folders


def delete_pycache():
global folders

for folder in folders:
if folder.endswith("__pycache__"):
shutil.rmtree(folder)

print("All __pycache__ files deleted.")
return None


def delete_migrations():
global folders

for folder in folders:
if folder.endswith("migrations"):
for item in os.listdir(folder):
if not item.endswith("__init__.py"):
os.remove(os.path.join(folder, item))

print("All migration files deleted.")
return None


def delete_sqlite3():
global base_dir
db_file = os.path.join(base_dir, "default.sqlite3")
if os.path.exists(db_file):
os.remove(db_file)


def main():
global folders

try:
get_directory_list()
delete_pycache()
delete_migrations()
delete_sqlite3()
print("All operations performed successfully.")
except Exception as e:
print("There was some error")


if __name__ == "__main__":
main()


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Jun 5, 2019 at 6:29 PM Chandrashekhar Singh <
chandrashekhar...@gmail.com> wrote:

> Better will be, delete all migrations, and again migrate
>
> On Fri, May 17, 2019, 12:51 PM RAJENDRA MYTHILI 17BIS0120 <
> rajendra.mythili2...@vitstudent.ac.in> wrote:
>
>> I'm facing the same issue ... Did you figure out what's wrong?
>>
>> On Saturday, October 6, 2018 at 6:28:09 AM UTC-7, Jaydeep Borkar wrote:
>>>
>>> When I try to register a user using Django form, it gives me "UNIQUE
>>> constraint failed: auth_user.username". When I tried registering the first
>>> user, it worked, but I couldn't see that entry in my database. When I tried
>>> registering the second user, it's giving me this error. Please, help me
>>> through this. I have spent a considerable amount of time on this and I'm
>>> stuck.
>>>
>>> This is my code:
>>>
>>> forms.py
>>> from django import forms
>>> from django.contrib.auth.models import User
>>> from volunteer.models import UserProfileInfo
>>>
>>> class UserForm(forms.ModelForm):
>>>
>>> class Meta():
>>> model = User
>>> fields = ('email','first_name','last_name')
>>>
>>>
>>>
>>>
>>> views.py
>>> from django.shortcuts import render
>>> from volunteer.forms import UserForm
>>>
>>>
>>>
>>> def register(request):
>>>
>>> registered = False
>>>
>>> if request.method =="POST" :
>>> user_form = UserForm(data=request.POST)
>>>
>>> if user_form.is_valid():
>>>
>>> user = user_form.save()
>>> user.save()
>>>
>>> registered = True
>>>
>>> else:
>>> print(user_form.errors)
>>>
>>> else:
>>> user_form = UserForm()
>>>
>>> return render(request, 'volunteer/volunteer.html',
>>>  {'user_form':user_form,
>>>   'registered':registered})
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> models.py
>>> from django.db import models
>>> from django.contrib.auth.models import User
>>>
>>> class UserProfileInfo(models.Model):
>>>
>>> user=models.OneToOneField(User)
>>>
>>> def __str__(self):
>>> return self.user.first_name
>>> return self.user.last_name
>>> return self.user.email
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> urls.py
>>> from django.conf.urls import url
>>>
>>> from . import views
>>>
>>> app_name = 'volunteer'
>>>
>>> urlpatterns = [
>>>
>>>  url(r'^', views.register, name='register'),
>>> ]
>>>
>>>
>>>
>>> admin.py
>>> from django.contrib import admin
>>> from volunteer.models import UserProfileInfo
>>>
>>> # Register your models here.
>>> admin.site.register(UserProfileInfo)
>>>
>>>
>>>
>>> volunteer.html file which has the user form
>>> 
>>> 
>>> 
>>> 
>>>
>>>
>>> 
>>>
>>>
>>> https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css";>
>>> https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
>>> ">
>>> https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js
>>> ">
>>>  https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js
>>> ">
>>>
>>> 
>>>
>>> 
>>>
>>>  
>>> {% if registered %}
>>>Thanks!
>>> {% else %}
>>>   Register
>>>
>>>
>>>  
>>> {% csrf_token %}
>>> {{ user_form.as_p }}
>>>  
>>>
>>>  {% endif %}
>>>
>>>  
>>>
>>>
>>>  
>>>
>>> 
>>> 
>>>
>>>
>>>
>>> I feel there's some problem in views.py or models.py, or volunteer.html.
>>> or maybe something else. Please, guide me through this.
>>> Thanks in advance.
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" gro

Bugs: cannot start runserver since Django 2.2.2

2019-06-05 Thread Bob Voorneveld
Since the security fix there were 2 problems:

The package cryptography is required (wasn't before updating the pip 
package). I'm running Django 2.2.2 with Daphne 2.3.0. See stacktrace:

Loading .env environment variables…
[05/Jun/2019 15:05:43] INFO [django.utils.autoreload:584] Watching for file 
changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/threading.py", line 917, in 
_bootstrap_inner
self.run()
  File "/usr/local/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/utils/autoreload.py"
, line 54, in wrapper
fn(*args, **kwargs)
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/core/management/commands/runserver.py"
, line 109, in inner_run
autoreload.raise_last_exception()
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/utils/autoreload.py"
, line 77, in raise_last_exception
raise _exception[1]
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/core/management/__init__.py"
, line 337, in execute
autoreload.check_errors(django.setup)()
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/utils/autoreload.py"
, line 54, in wrapper
fn(*args, **kwargs)
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/__init__.py"
, line 24, in setup
apps.populate(settings.INSTALLED_APPS)
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/apps/registry.py"
, line 91, in populate
app_config = AppConfig.create(entry)
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/apps/config.py"
, line 116, in create
mod = import_module(mod_path)
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/importlib/__init__.py"
, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1006, in _gcd_import
  File "", line 983, in _find_and_load
  File "", line 967, in _find_and_load_unlocked
  File "", line 677, in _load_unlocked
  File "", line 728, in exec_module
  File "", line 219, in 
_call_with_frames_removed
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/channels/apps.py"
, line 6, in 
import daphne.server
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/daphne/server.py"
, line 32, in 
from .ws_protocol import WebSocketFactory
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/daphne/ws_protocol.py"
, line 6, in 
from autobahn.twisted.websocket import (
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/autobahn/twisted/__init__.py"
, line 58, in 
from autobahn.twisted.wamp import ApplicationSession
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/autobahn/twisted/wamp.py"
, line 50, in 
from autobahn.wamp import protocol, auth
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/autobahn/wamp/auth.py"
, line 43, in 
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
ModuleNotFoundError: No module named 'cryptography'




Installing the package fixed the above, but couldn't find any required 
dependencies for the package?

Another one is that starting runserver, it crashes immediately. This is the 
stacktrace. Maybe something broke with StatReloader? I'm running Django in 
a docker-compose environment.

As a workaround I reverted back to Django 2.2.1, please let me know how the 
latest problem can be mitigated. And I'm curious how cryptography is 
suddenly required.

Loading .env environment variables…
[05/Jun/2019 15:28:12] INFO [django.utils.autoreload:584] Watching for file 
changes with StatReloader
Performing system checks...
Traceback (most recent call last):

  File "manage.py", line 15, in 
execute_from_command_line(sys.argv)
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/core/management/__init__.py"
, line 381, in execute_from_command_line
utility.execute()
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/core/management/__init__.py"
, line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/core/management/base.py"
, line 323, in run_from_argv
self.execute(*args, **cmd_options)
  File 
"/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/p

Re: Bugs: cannot start runserver since Django 2.2.2

2019-06-05 Thread Ramiro Morales
Hi Bob,

Are you sure aren't Autobahn and/or Twisted (or any another lib) being
upgraded at the same time?
>From the look of the traceback it seems there is a sizeable list of chained
dependencies and it shows clearly cryptography is being actually imported
from autobahn.

On Wed, Jun 5, 2019 at 10:38 AM Bob Voorneveld 
wrote:

> Since the security fix there were 2 problems:
>
> The package cryptography is required (wasn't before updating the pip
> package). I'm running Django 2.2.2 with Daphne 2.3.0. See stacktrace:
>
> Loading .env environment variables…
> [05/Jun/2019 15:05:43] INFO [django.utils.autoreload:584] Watching for
> file changes with StatReloader
> Exception in thread django-main-thread:
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.7/threading.py", line 917, in
> _bootstrap_inner
> self.run()
>   File "/usr/local/lib/python3.7/threading.py", line 865, in run
> self._target(*self._args, **self._kwargs)
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/utils/autoreload.py"
> , line 54, in wrapper
> fn(*args, **kwargs)
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/core/management/commands/runserver.py"
> , line 109, in inner_run
> autoreload.raise_last_exception()
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/utils/autoreload.py"
> , line 77, in raise_last_exception
> raise _exception[1]
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/core/management/__init__.py"
> , line 337, in execute
> autoreload.check_errors(django.setup)()
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/utils/autoreload.py"
> , line 54, in wrapper
> fn(*args, **kwargs)
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/__init__.py"
> , line 24, in setup
> apps.populate(settings.INSTALLED_APPS)
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/apps/registry.py"
> , line 91, in populate
> app_config = AppConfig.create(entry)
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/apps/config.py"
> , line 116, in create
> mod = import_module(mod_path)
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/importlib/__init__.py"
> , line 127, in import_module
> return _bootstrap._gcd_import(name[level:], package, level)
>   File "", line 1006, in _gcd_import
>   File "", line 983, in _find_and_load
>   File "", line 967, in
> _find_and_load_unlocked
>   File "", line 677, in _load_unlocked
>   File "", line 728, in exec_module
>   File "", line 219, in
> _call_with_frames_removed
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/channels/apps.py"
> , line 6, in 
> import daphne.server
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/daphne/server.py"
> , line 32, in 
> from .ws_protocol import WebSocketFactory
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/daphne/ws_protocol.py"
> , line 6, in 
> from autobahn.twisted.websocket import (
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/autobahn/twisted/__init__.py"
> , line 58, in 
> from autobahn.twisted.wamp import ApplicationSession
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/autobahn/twisted/wamp.py"
> , line 50, in 
> from autobahn.wamp import protocol, auth
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/autobahn/wamp/auth.py"
> , line 43, in 
> from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
> ModuleNotFoundError: No module named 'cryptography'
>
>
>
>
> Installing the package fixed the above, but couldn't find any required
> dependencies for the package?
>
> Another one is that starting runserver, it crashes immediately. This is
> the stacktrace. Maybe something broke with StatReloader? I'm running Django
> in a docker-compose environment.
>
> As a workaround I reverted back to Django 2.2.1, please let me know how
> the latest problem can be mitigated. And I'm curious how cryptography is
> suddenly required.
>
> Loading .env environment variables…
> [05/Jun/2019 15:28:12] INFO [django.utils.autoreload:584] Watching for
> file changes with StatReloader
> Performing system checks...
> Traceback (most recent call last):
>
>   File "manage.py", line 15, in 
> execute_from_command_line(sys.argv)
>   File
> "/home/docker/.local/share/virtualenvs/dropper-TxELQAPU/lib/python3.7/site-packages/django/core/management/__init__.py"
> , line 381, in execut

Re: How to migrate MySQL -> PostgreSQL?

2019-06-05 Thread phep

Hi,

Would you mind giving details why dumping/reloading JSON should not be used 
in production (putting aside HA problems, for sure).


TIA

Le 05/06/2019 à 14:01, Devender Kumar a écrit :

Hi,
*It's very complicated with not much explanation in question.*
Its depend on where you want to do this process Development or Production.
If it is development then and not holding a very large amount of data.
then its not very complicated
  dump JSON > change database engine > load JSON.
If its production end then you might have to write some scripts to copy data 
from one database (MySQL) to dump Into another database (PostgreSQL) in 
between you can use transition state of JSON OR XML


Thank you


On Tue, Jun 4, 2019 at 2:46 PM Julien Enselme 
mailto:julien.ense...@bureauxlocaux.com>> 
wrote:


Hi,

At my company we recently made a switch from MySQL to PG. We used
https://pgloader.io/ to load the data from MySQL to PG. It reliable and
quite fast (we had about 2GO of data to migrate in multiple table). The
tool will handle table creation and data migration. As @Kiran said, try
first in a test env. It may take a while depending on the amount of code
that relies on MySQL specific features. I hope this helps!

Regard,
Julien Enselme
Développeur chez BureauxLocaux


Le mar. 4 juin 2019 à 00:56, Kiran Capoor mailto:kirancapoo...@gmail.com>> a écrit :

Hi,

As said by ankhi, change to pgsql in settings before that use the
django fixtures feature to take a backup of the data etc. try in
test env only as this has breaking potential.

Regards,
Kiran Capoor

On Tue, 4 Jun 2019 at 01:33, Ankhi Roy mailto:montip...@gmail.com>> wrote:

Hey Victor,

Do you mean to use postgresql instead of mysql,  if so please
change database settings in settings.py. However,  I am not sure
how will you migrate your existing mysql tables and contents to
postgresql. Just a workaround you can recreate tables in
postgresql and re add the data. There must be an efficient way
though.

Thanks
Ankhi

On Mon, Jun 3, 2019, 8:21 PM Victor Porton mailto:por...@narod.ru>> wrote:

How to migrate a production database MySQL -> PostgreSQL?

(MySQL has several bugs, I want to try something other on my
production server.)

-- 
You received this message because you are subscribed to the

Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails
from it, send an email to
django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to
django-users@googlegroups.com
.
Visit this group at
https://groups.google.com/group/django-users.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/97a3c018-86ee-462a-a21a-6d2a7971adc1%40googlegroups.com

.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the

Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from
it, send an email to django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to
django-users@googlegroups.com
.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/CABUQWg_hm7U__cwKJvFvvvR3osuz-MtswCL1YLA74pGdEvp_PA%40mail.gmail.com

.
For more options, visit https://groups.google.com/d/optout.

-- 
Sent from iPhone


-- 
You received this message because you are subscribed to the Google

Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com


Re: Django user profile shared among different apps

2019-06-05 Thread Chetan Ganji
just create another model in the accounts app and put a one to one key to
the User Model of django.
Import it from settings instead of harcoding it. Give it a relevant
related_name.

Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Jun 5, 2019 at 6:23 PM Gaurav Sahu  wrote:

> Hy Everyone,
> I have a Django website which has multiple apps one of the apps is
> accounts app. accounts app is responsible for user sign up and
> authentication. Now I want to create a user profile in my website and that
> user will be the same across all of my web apps. how can I implement this?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/85bdf45d-ed9e-4a85-a9ce-df25e8b9e2c3%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMKMUjsYPYPNCsC5OSGbPZC8DUNhsjPNvuvcjGPMj-dZ4TVYJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: What's the best way to inherit boolean values from a model?

2019-06-05 Thread Tal
Awesome! Simple and DRY. Thanks!

On Wednesday, June 5, 2019 at 5:07:17 AM UTC-6, RyuCoder wrote:
>
> No need for inherit permissions.  As it will increase one more if 
> condition to be checked. 
> But, whenever a new user is created, you have to read the values from its 
> companys permissions and set them for the current user. 
> If companies permissions are updated, all of its employees permissions 
> needs to be updated as well. 
>
> This is a typical example of a Nested CRUD. 
>
>
>
> class BasePermissions(models.Model):
> allow_blog_access = models.BooleanField(default=True)
> allow_shop_access = models.BooleanField(default=True)
> allow_admin_access = models.BooleanField(default=True)
>
> class Meta:
> abstract = True
>
>
> class Company(BasePermissions):
> name = models.CharField(max_length=255)
>
>
> class CustomUser(BasePermissions, AbstractUser):
> company = models.ForeignKey(Company, on_delete=models.CASCADE, 
> related_name="customuser")
>
>
>
> Cheers!
>
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji...@gmail.com 
> http://ryucoder.in
>
>
> On Wed, Jun 5, 2019 at 4:26 AM Tal > wrote:
>
>> Lets say I have 2 models:
>>
>>
>> class Company(models.Model):
>>  name = models.CharField(...)
>>  allow_blog_access = models.BooleanField(...)
>>  allow_shop_access = models.BooleanField(...)
>>  allow_admin_access = models.BooleanField(...)
>>
>>
>> class User(AbstractUser):
>>  company = models.ForeignKey(Company, ...)
>>  ...
>>
>>
>>
>> Here, users can be assigned to a company, and when a user tries to access 
>> a particular webpage,
>> the view can check:
>>
>>- Does this user's company have access to this area (ex. the blog 
>>app)?
>>
>>
>> This is great. That means access to particular areas (or apps) of the 
>> site can be controlled at the company level.
>> When you create a user, you just assign him to a company, and whatever 
>> the company is allowed to access, he is
>> as well. It makes updating access a lot easier too, when you can change 
>> it in one place (at the company level), instead
>> of doing it for every user.
>>
>> The problem I'm having is that one or two users that are part of a 
>> particular company need access to most of, but
>> not all of, the areas the company has access to.
>>
>> What's the best way to implement this?
>>
>> The main thing I can think of is to have the User class also have Boolean 
>> fields for allow_blog_access, allow_shop_access
>> and allow_admin_access, but add another field called inherit_permissions 
>> (also boolean). It would look like this:
>>
>>
>> class Company(models.Model):
>>  name = models.CharField(...)
>>  allow_blog_access = models.BooleanField(...)
>>  allow_shop_access = models.BooleanField(...)
>>  allow_admin_access = models.BooleanField(...)
>>
>>
>> class User(AbstractUser):
>>  company = models.ForeignKey(Company, ...)
>>  allow_blog_access = models.BooleanField(...)
>>  allow_shop_access = models.BooleanField(...)
>>  allow_admin_access = models.BooleanField(...)
>>  inherit_permission = models.BooleanField(...)
>>  ...
>>
>>
>>
>> If inherit_permissions for a user is set, the view should look at the 
>> permissions of the company the user belongs to 
>> (request.user.company.allow_blog_access).
>> If inherit_permissions for a user is not set, the view should look at the 
>> permissions of the user (request.user.allow_blog_access).
>>
>> Is there a better way to do this? Or is that the simplest?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/c0051d28-de5d-427f-87da-4bd986734f69%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1ad82488-02c3-482a-ba84-fc529c066967%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: What's the best way to inherit boolean values from a model?

2019-06-05 Thread Chetan Ganji
RE : If companies permissions are updated, all of its employees permissions
needs to be updated as well.

Just make sure to use transaction for this.
e.g.

from django.db import DatabaseError, transaction
with transaction.atomic():
# code to update company permissions

# code to update its employees permissions

pass




Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Jun 5, 2019 at 8:52 PM Tal  wrote:

> Awesome! Simple and DRY. Thanks!
>
> On Wednesday, June 5, 2019 at 5:07:17 AM UTC-6, RyuCoder wrote:
>>
>> No need for inherit permissions.  As it will increase one more if
>> condition to be checked.
>> But, whenever a new user is created, you have to read the values from its
>> companys permissions and set them for the current user.
>> If companies permissions are updated, all of its employees permissions
>> needs to be updated as well.
>>
>> This is a typical example of a Nested CRUD.
>>
>>
>>
>> class BasePermissions(models.Model):
>> allow_blog_access = models.BooleanField(default=True)
>> allow_shop_access = models.BooleanField(default=True)
>> allow_admin_access = models.BooleanField(default=True)
>>
>> class Meta:
>> abstract = True
>>
>>
>> class Company(BasePermissions):
>> name = models.CharField(max_length=255)
>>
>>
>> class CustomUser(BasePermissions, AbstractUser):
>> company = models.ForeignKey(Company, on_delete=models.CASCADE,
>> related_name="customuser")
>>
>>
>>
>> Cheers!
>>
>>
>> Regards,
>> Chetan Ganji
>> +91-900-483-4183
>> ganji...@gmail.com
>> http://ryucoder.in
>>
>>
>> On Wed, Jun 5, 2019 at 4:26 AM Tal  wrote:
>>
>>> Lets say I have 2 models:
>>>
>>>
>>> class Company(models.Model):
>>>  name = models.CharField(...)
>>>  allow_blog_access = models.BooleanField(...)
>>>  allow_shop_access = models.BooleanField(...)
>>>  allow_admin_access = models.BooleanField(...)
>>>
>>>
>>> class User(AbstractUser):
>>>  company = models.ForeignKey(Company, ...)
>>>  ...
>>>
>>>
>>>
>>> Here, users can be assigned to a company, and when a user tries to
>>> access a particular webpage,
>>> the view can check:
>>>
>>>- Does this user's company have access to this area (ex. the blog
>>>app)?
>>>
>>>
>>> This is great. That means access to particular areas (or apps) of the
>>> site can be controlled at the company level.
>>> When you create a user, you just assign him to a company, and whatever
>>> the company is allowed to access, he is
>>> as well. It makes updating access a lot easier too, when you can change
>>> it in one place (at the company level), instead
>>> of doing it for every user.
>>>
>>> The problem I'm having is that one or two users that are part of a
>>> particular company need access to most of, but
>>> not all of, the areas the company has access to.
>>>
>>> What's the best way to implement this?
>>>
>>> The main thing I can think of is to have the User class also have
>>> Boolean fields for allow_blog_access, allow_shop_access
>>> and allow_admin_access, but add another field called inherit_permissions
>>> (also boolean). It would look like this:
>>>
>>>
>>> class Company(models.Model):
>>>  name = models.CharField(...)
>>>  allow_blog_access = models.BooleanField(...)
>>>  allow_shop_access = models.BooleanField(...)
>>>  allow_admin_access = models.BooleanField(...)
>>>
>>>
>>> class User(AbstractUser):
>>>  company = models.ForeignKey(Company, ...)
>>>  allow_blog_access = models.BooleanField(...)
>>>  allow_shop_access = models.BooleanField(...)
>>>  allow_admin_access = models.BooleanField(...)
>>>  inherit_permission = models.BooleanField(...)
>>>  ...
>>>
>>>
>>>
>>> If inherit_permissions for a user is set, the view should look at the
>>> permissions of the company the user belongs to
>>> (request.user.company.allow_blog_access).
>>> If inherit_permissions for a user is not set, the view should look at
>>> the permissions of the user (request.user.allow_blog_access).
>>>
>>> Is there a better way to do this? Or is that the simplest?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/c0051d28-de5d-427f-87da-4bd986734f69%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post 

Re: What's the best way to inherit boolean values from a model?

2019-06-05 Thread Tal
Didn't know it was so simple to do that - I'll make sure to do it.
Thanks


On Wednesday, June 5, 2019 at 9:32:30 AM UTC-6, RyuCoder wrote:
>
> RE : If companies permissions are updated, all of its employees 
> permissions needs to be updated as well. 
>
> Just make sure to use transaction for this.
> e.g. 
>
> from django.db import DatabaseError, transaction
> with transaction.atomic():
> # code to update company permissions 
>
> # code to update its employees permissions
>
> pass
>
>
>
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji...@gmail.com 
> http://ryucoder.in
>
>
> On Wed, Jun 5, 2019 at 8:52 PM Tal > wrote:
>
>> Awesome! Simple and DRY. Thanks!
>>
>> On Wednesday, June 5, 2019 at 5:07:17 AM UTC-6, RyuCoder wrote:
>>>
>>> No need for inherit permissions.  As it will increase one more if 
>>> condition to be checked. 
>>> But, whenever a new user is created, you have to read the values from 
>>> its companys permissions and set them for the current user. 
>>> If companies permissions are updated, all of its employees permissions 
>>> needs to be updated as well. 
>>>
>>> This is a typical example of a Nested CRUD. 
>>>
>>>
>>>
>>> class BasePermissions(models.Model):
>>> allow_blog_access = models.BooleanField(default=True)
>>> allow_shop_access = models.BooleanField(default=True)
>>> allow_admin_access = models.BooleanField(default=True)
>>>
>>> class Meta:
>>> abstract = True
>>>
>>>
>>> class Company(BasePermissions):
>>> name = models.CharField(max_length=255)
>>>
>>>
>>> class CustomUser(BasePermissions, AbstractUser):
>>> company = models.ForeignKey(Company, on_delete=models.CASCADE, 
>>> related_name="customuser")
>>>
>>>
>>>
>>> Cheers!
>>>
>>>
>>> Regards,
>>> Chetan Ganji
>>> +91-900-483-4183
>>> ganji...@gmail.com
>>> http://ryucoder.in
>>>
>>>
>>> On Wed, Jun 5, 2019 at 4:26 AM Tal  wrote:
>>>
 Lets say I have 2 models:


 class Company(models.Model):
  name = models.CharField(...)
  allow_blog_access = models.BooleanField(...)
  allow_shop_access = models.BooleanField(...)
  allow_admin_access = models.BooleanField(...)


 class User(AbstractUser):
  company = models.ForeignKey(Company, ...)
  ...



 Here, users can be assigned to a company, and when a user tries to 
 access a particular webpage,
 the view can check:

- Does this user's company have access to this area (ex. the blog 
app)?


 This is great. That means access to particular areas (or apps) of the 
 site can be controlled at the company level.
 When you create a user, you just assign him to a company, and whatever 
 the company is allowed to access, he is
 as well. It makes updating access a lot easier too, when you can change 
 it in one place (at the company level), instead
 of doing it for every user.

 The problem I'm having is that one or two users that are part of a 
 particular company need access to most of, but
 not all of, the areas the company has access to.

 What's the best way to implement this?

 The main thing I can think of is to have the User class also have 
 Boolean fields for allow_blog_access, allow_shop_access
 and allow_admin_access, but add another field called 
 inherit_permissions (also boolean). It would look like this:


 class Company(models.Model):
  name = models.CharField(...)
  allow_blog_access = models.BooleanField(...)
  allow_shop_access = models.BooleanField(...)
  allow_admin_access = models.BooleanField(...)


 class User(AbstractUser):
  company = models.ForeignKey(Company, ...)
  allow_blog_access = models.BooleanField(...)
  allow_shop_access = models.BooleanField(...)
  allow_admin_access = models.BooleanField(...)
  inherit_permission = models.BooleanField(...)
  ...



 If inherit_permissions for a user is set, the view should look at the 
 permissions of the company the user belongs to 
 (request.user.company.allow_blog_access).
 If inherit_permissions for a user is not set, the view should look at 
 the permissions of the user (request.user.allow_blog_access).

 Is there a better way to do this? Or is that the simplest?

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to django...@googlegroups.com.
 To post to this group, send email to django...@googlegroups.com.
 Visit this group at https://groups.google.com/group/django-users.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/c0051d28-de5d-427f-87da-4bd986734f69%40googlegroups.com
  
 

Re: My developers have run amok

2019-06-05 Thread Dan Davis
>
> Are you sure?
> My (possibly flawed) understanding is that if you can make the change in
> a single transaction, no-one else can see what is happening until it is
> committed. Effectively that would be an instantaneous change.
> Depending on your data architecture you might need to make some parts
> read-only for the 30 minutes prior to committing.

The transaction can be atomic if it is a database such as PostgreSQL that
offers DDL changes in a transaction.   The issue is that rather than
updating the code for the web application in place, and then running
migrations, my CI/CD pipeline will instead bring up an entirely new set of
servers.   This makes a more isolated change to the environment, and
deployment also will take care of OS patching and such, but the old web
servers will still be online and querying the database.   They may will be
querying a column that no longer exists, which is a form of "Read after
Write" synchronization problem.

I think with an alternative CI/CD, in the cloud or elsewhere, this would
not be an issue.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFzonYbMEJ4k43%2BjxnSOojOgTMO9Y6%3Dc5W2DCrCWrNnsRMuEeQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Existing database for users to use django user auths

2019-06-05 Thread Vijay Khemlani
Yes, you can write your own Authentication Backend with your custom
authentication logic

https://docs.djangoproject.com/en/2.2/topics/auth/customizing/

On Wed, Jun 5, 2019 at 8:53 AM michael ababao 
wrote:

> I am new to django and i would like to know if it is possible to use the
> django user authentication using a different database for users?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/688efd6f-8768-44e0-b9aa-79e6b508bfb4%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei0MiUifhW3NFU8rosK-agS8NjMO3otm%2BUki1g2--WCyEA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Order_by ManyToMany relation?

2019-06-05 Thread Mei B
I have a form for a model that contains a ManyToMany relationship to model 
B.
By default, manytomany relationship on forms are SelectMuliple and orders 
them by alphabetical.
How can I order by if they already have a relation?

In my forms.py

class FormA(forms.ModelForm):
class Meta:
model = models.A

def __init___(self, *args, **kwargs):
  super(FormA, self).__init__(*args, **kwargs)
  self.fields["b"].queryset = models.B.objects.order_by(???)

If model B has objects: "a, a1, a2, b, b2"
And model A has a many to many relationship with B's "a, a2, b2"
How can I order the objects so it'll show "a, a2, b2, a1, b" on the form?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e48671f7-9f21-49c7-b664-0545161d0fa7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Handling two forms at different pages.

2019-06-05 Thread Ashutosh Kumar
Hi,

Actually I have two forms at two different pages and the second page is the
extension of first form.

Basically the first page has some fields and continue button to the next
page, and next page has some fields and save button.

So once user will click to continue I don't want to save the data, instead
I want to save all together when the user will hit save button to the next
page.

My question is how to do this in dango.

Your help is much appreciated.

Regards,

Ashutosh

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAcNNfJG11_t5VLGE%3Dm62D5WM5Y8sSkzTMw_ZiGE1vZMk3Ar%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Multitentant login

2019-06-05 Thread Sebastian Jung
Hello,

i have a Login Form with 3 Fields: Mandatename, Username and Password. Now 
the user login now with a Mandatename. There are a global database where 
there are a relation between mandate name and a further database. All 
Querys now from this User goes then to this database.

Example:

User A login with Mandatename Mandate_A. In global Database there are a 
entry Mandate_A to Database with Name "1". Now i want that all querys from 
request from User A to Database 1 goes. Another User B Login with 
Mandate_B. In global Database there are a Entry to Database "2". All Querys 
from this User goes to Database 2. 

Is this possible?

Regards

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b8bc6fb3-f453-4b5c-a39d-31b39dc73b9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


list_filter no longer does Boolean?

2019-06-05 Thread Lachlan Musicman
Hola,

I seem to remember when list_filter did booleans - does it no longer?

Cheers
L.

-- 
--
"The fact that you're still saying something like 'feminism gone mad'
suggests that feminism hasn't gone mad ENOUGH yet."

Helen Zaltzman / @HelenZaltzman
https://twitter.com/HelenZaltzman/status/1065384934846545920

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGBeqiNQ-4c1ffJAURxYpzwZY8U1jmZ7MB_BMHNeoLwZybF3-w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: list_filter no longer does Boolean?

2019-06-05 Thread Lachlan Musicman
On Thu, 6 Jun 2019 at 16:36, Lachlan Musicman  wrote:

> Hola,
>
> I seem to remember when list_filter did booleans - does it no longer?
>


Oh. I see that it does - if it's a BooleanField, but not for a method on
the Model class?


--
"The fact that you're still saying something like 'feminism gone mad'
suggests that feminism hasn't gone mad ENOUGH yet."

Helen Zaltzman / @HelenZaltzman
https://twitter.com/HelenZaltzman/status/1065384934846545920

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGBeqiPimCrPXGyms36PtaS46KUwfSX0pdjabHL4S_doaeLHjw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.