Django 1.7+ default_permissions

Source: Internet
Author: User

Because do caption to do authority design. In the design of the core class need to do a good job of the basic design of authority. Django 1.7+ later django.db.modes new features default_permissions, official document vague.

decided to explore under their own, do not want to analyze the code, then introduce a bug, direct observation of the core line.

Introduce the Bug method:

Class Basemodel (models. Model):    # ...    . Class Meta:        default_permissions= ' Add ' #should be (' Add ', ' Change ',...)

The error is as follows:

Traceback (most recent): File "C:\Users\tommy.yu\Desktop\Captain\Captain-master\codes\Captain\manage.py", Line ten, in <module> execute_from_command_line (SYS.ARGV) File "C:\Python27\lib\site-packages\ django-1.7.2-py2.7.egg\django\core\management\__init__.py ", line 385, in Execute_from_command_line Utility.execute ( ) File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\core\management\__init__.py", line 377, in Execute Self.fetch_command (subcommand). RUN_FROM_ARGV (SELF.ARGV) File "C:\Python27\lib\site-packages\ django-1.7.2-py2.7.egg\django\core\management\base.py ", line 288, in RUN_FROM_ARGV Self.execute (*args, **options.__ dict__) File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\core\management\base.py", line 338, in Execute output = Self.handle (*args, **options) File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\ core\management\commands\migrate.py ", line 165, in handle emit_post_migrate_signal (Created_modEls, Self.verbosity, self.interactive, Connection.alias) File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg \django\core\management\sql.py ", line 268, in emit_post_migrate_signal using=db) File" C:\Python27\lib\site-packages\ django-1.7.2-py2.7.egg\django\dispatch\dispatcher.py ", line 198, in Send response = Receiver (signal=self, Sender=sende R, **named) File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\contrib\auth\management\__init__.py ", line, in Create_permissions Permission.objects.using (using). Bulk_create (perms) File" C:\Python27\lib\site-pack ages\django-1.7.2-py2.7.egg\django\db\models\query.py ", line 409, in Bulk_create Self._batched_insert (objs_without_ PK, fields, batch_size) File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\query.py", line 938, in _batched_insert using=self.db) File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\ manager.py ", line, Manager_method return getattr (Self.get_queryset (), name) (*args, **kwargs) File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django \db\models\query.py ", line 921, in _insert return Query.get_compiler (using=using). Execute_sql (return_id) File" C:\Pyth    on27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sql\compiler.py ", line 920, in Execute_sql Cursor.execute (SQL, params) File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\backends\ utils.py ", line Bayi, in Execute return super (Cursordebugwrapper, self). Execute (SQL, params) File" C:\Python27\lib\site- packages\django-1.7.2-py2.7.egg\django\db\backends\utils.py ", line +, in Execute return self.cursor.execute (SQL, params) File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\utils.py", line 94, in __exit__ Six.rera Ise (Dj_exc_type, Dj_exc_value, Traceback) File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\ backends\utils.py ", line +, in Execute return self.cursor.execute (SQL,params) File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\backends\sqlite3\base.py", line 486, In Execute return Database.Cursor.execute (self, query, params) django.db.utils.IntegrityError:columns content_type_id , codename is not unique

  

Add print directly to the final file C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\backends\sqlite3\base.py Statements such as XXX. As follows:

    def execute (Self, query, Params=none):        If params was None:            return Database.Cursor.execute (self, query)        query = self.convert_query (query)        print query,params# adds the print        return Database.Cursor.execute (self, query , params)

Migrate again, and observe sql:

Select "Django_migrations". " App "," Django_migrations "." Name "from" Django_migrations "() Operations to perform:synchronize unmigrated apps:mptt Apply all migrations:admin, C  Ore, ContentTypes, auth, sessionssynchronizing apps without migrations:creating tables ...  Installing Custom SQL ... Installing indexes ... Running migrations:no migrations to apply. Select "Django_content_type". " ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE (" Django_content_type "." Model "=? and "Django_content_type". " App_label "=?) LIMIT (' LogEntry ', ' admin ') select "Auth_permission". " content_type_id "," auth_permission "." Codename "from" Auth_permission "INNER joins" Django_content_type "On (" Auth_permission "." content_type_id "=" Django_content_type "." ID ") WHERE" Auth_permission "." Content_type_id "in (?) ORDER by "Django_content_type". " App_label "ASC," Django_content_type "." Model "ASC," auth_permission "." Codename "ASC (1,) Select "Django_content_type". " ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE" Django_content_type "." App_label "=? ORDER by "Django_content_type". " Name "ASC (' admin ')," select "Django_content_type". " ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE (" Django_content_type "." Model "=? and "Django_content_type". " App_label "=?) LIMIT (' permission ', ' auth ') select "Django_content_type". " ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE (" Django_content_type "." Model "=? and "Django_content_type". " App_label "=?) LIMIT (' group ', ' auth ') select "Django_content_type". " ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE (" Django_content_type "." Model "=? and "DjaNgo_content_type "." App_label "=?) LIMIT (' user ', ' auth ') select "Auth_permission". " content_type_id "," auth_permission "." Codename "from" Auth_permission "INNER joins" Django_content_type "On (" Auth_permission "." content_type_id "=" Django_content_type "." ID ") WHERE" Auth_permission "." content_type_id "In (?,?,?) ORDER by "Django_content_type". " App_label "ASC," Django_content_type "." Model "ASC," auth_permission "." Codename "ASC (2, 3, 4) Select" Django_content_type "." ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE" Django_content_type "." App_label "=? ORDER by "Django_content_type". " Name "ASC (' auth ',) select" Django_content_type "." ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE (" Django_content_type "." Model "=? and "Django_content_type". " App_label "=?) LIMIT (' contenttype ', ' contenttypes ') select "Auth_permission". "content_type_id "," auth_permission "." Codename "from" Auth_permission "INNER joins" Django_content_type "On (" Auth_permission "." content_type_id "=" Django_content_type "." ID ") WHERE" Auth_permission "." Content_type_id "in (?) ORDER by "Django_content_type". " App_label "ASC," Django_content_type "." Model "ASC," auth_permission "." Codename "ASC (5,) select" Django_content_type "." ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE" Django_content_type "." App_label "=? ORDER by "Django_content_type". " Name "ASC (' contenttypes ',) select" Django_content_type "." ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE (" Django_content_type "." Model "=? and "Django_content_type". " App_label "=?) LIMIT (' Session ', ' Sessions ') select "Auth_permission". " content_type_id "," auth_permission "." Codename "from" Auth_permission "INNER JOIN" Django_content_Type "On (" Auth_permission ".") content_type_id "=" Django_content_type "." ID ") WHERE" Auth_permission "." Content_type_id "in (?) ORDER by "Django_content_type". " App_label "ASC," Django_content_type "." Model "ASC," auth_permission "." Codename "ASC (6,) select" Django_content_type "." ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE" Django_content_type "." App_label "=? ORDER by "Django_content_type". " Name "ASC (' Sessions ',) select" Django_content_type "." ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE (" Django_content_type "." Model "=? and "Django_content_type". " App_label "=?) LIMIT (' tag ', ' Core ') select "Django_content_type". " ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE (" Django_content_type "." Model "=? and "Django_content_type". " App_labEl "=?) LIMIT (' contenttype ', ' Core ') select "Django_content_type". " ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE (" Django_content_type "." Model "=? and "Django_content_type". " App_label "=?) LIMIT (' menu ', ' Core ') select "Django_content_type". " ID "," django_content_type "." Name "," Django_content_type "." App_label "," Django_content_type "." Model "from" Django_content_type "WHERE (" Django_content_type "." Model "=? and "Django_content_type". " App_label "=?) LIMIT (' page ', ' Core ') select "Auth_permission". " content_type_id "," auth_permission "." Codename "from" Auth_permission "INNER joins" Django_content_type "On (" Auth_permission "." content_type_id "=" Django_content_type "." ID ") WHERE" Auth_permission "." content_type_id "in (?,?,?,?) ORDER by "Django_content_type". " App_label "ASC," Django_content_type "." Model "ASC," auth_permission "." Codename "ASC (8, 9, 7) INSERT into" Auth_permission "(" Name ","Content_type_id", "codename") select? As "name",? As "content_type_id",? As "codename" UNION all SELECT?,?,? UNION all SELECT?,?,? UNION all SELECT?,?,? UNION all SELECT?,?,? UNION all SELECT?,?,? UNION all SELECT?,?,? (U ' Can a page ', ten, ' A_page ', U ' can D page ', ten, ' D_page ', U ' can D page ', ten, ' d_page ', ' can_add_% (Class) s ', ' + ', ' add ', ' C An_change_% (Class) s ', ten, ' Change ', ' can_delete_% (Class) s ', ', ' delete ', ' can_read_% (Class) s ', ' ten, ' read ') Traceback ( Most recent call last):

  

Django 1.7+ default_permissions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.