How can I tell django 1.7 to put migration into specific folder

Maxim Leonovich

I'm running into quite interesting situation.

I need to extend default django's Group model with some fields. I tried to use inheritance first, e.g. inherit from Group model and change some references, but seems I can't change all needed references, so, this way completely breaks django permission system.

Then I found this answer: How do I extend the Django Group model? where guy suggested to use field.contribute_to_class() method.

I have put this adjustment right above the model definition in < myapp >. (don't ask me why do I need roles for group, it's not my idea, I just need them :D)

if not hasattr(Group, 'roles'):
    field = models.ManyToManyField(
        Role, verbose_name=_('roles'), blank=True,
        help_text=_('List of roles attached to this group'),
           related_name='groups')
    field.contribute_to_class(Group, 'roles')


class MyGroup(Group):

    class Meta:
        proxy = True

    def _sync_permissions(self):
        """
            This method will sync group permissions with all attached Roles.
        """
        self.permissions.clear()
        for role in self.roles.all():
            self.permissions.add(role.permissions)
        self.save()

This part seems to be working (it really modifies django.contrib.auth.models.Group model)

But what I need next is to generate a migration for the Group model. If I simply run ./manage.py makemigrations <myapp> it generates a migration for Group model, but tries to put it inside django.contrib.auth application, that is definitely not what I need.

So, my question here is:

Is there a way to tell django to generate a migration for Group model, but not to create a migration file under python libs directory, but rather create it inside < myapp > or just output the migration code?

sax

the location where django looks for migrations cn be custominzed using MIGRATION_MODULES in your settings.py, anyway this means that ALL the migrations (not only the new) must be there. You need to copy the original migrations and manually update them when you upgrade Django

You can create a dedicated package so to not clash with your migrations Es.

MIGRATION_MODULES = {
     'django.contrib.auth' : 'myapp.auth_migrations',
     'myapp': 'myapp.migrations'  # this line is only to clarify. IT'S NOT NEEDED AT ALL 
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How do I only put dependencies into a specific folder for yarn?

分類Dev

How can I get a specific folder with a specific folders sibling in python

分類Dev

How can I move specific files from within a folder when that folder is added to a directory?

分類Dev

How can I tell if my columns are R1C1 reference style with excel vba?

分類Dev

Using Powershell and Test-Path, how can I tell the difference between a "folder doesn't exist" and "access denied"

分類Dev

How can I tell a function enters kernel or not

分類Dev

How do I tell Pyinstaller to use an .EXE thats in the Scripts folder?

分類Dev

How can I create a batch file to put file names in a .txt in a specific way

分類Dev

Magento - How can I tell if I'm on a "My Account" page?

分類Dev

How can I tell which user limit I am running into?

分類Dev

How can I tell if I am out of inotify watches?

分類Dev

How can I tell how many bits my ssh key is?

分類Dev

How to set .NET Error Pages for a specific folder in IIS 7?

分類Dev

Thunar - can I change the sorting method for one specific folder?

分類Dev

How can I put Tolkeins Elvish in Java

分類Dev

How can I put a "+" below each table?

分類Dev

How can I programmatically tell if a filename matches a shell glob pattern?

分類Dev

XMLEventWriter: how can I tell it to write empty elements?

分類Dev

How can I tell Selenium to press cancel on a print popup?

分類Dev

How can I tell Selenium to press cancel on a print popup?

分類Dev

How can I tell which mysql user edited a table in mysql

分類Dev

Ember: How can I tell if peekAll returns any models?

分類Dev

How can I tell if my current PowerShell session is over SSH?

分類Dev

How can I tell meson in which directories to look for dependencies?

分類Dev

How can I tell if my vector matches the variable values in r?

分類Dev

How can I tell through the Stripe API if a connected account is complete?

分類Dev

How can I tell which web server Zimbra 8.0.6 is running?

分類Dev

How can I tell whether a build is Debian-based?

分類Dev

How can I tell Brunch not to concatenate javascript files?

Related 関連記事

  1. 1

    How do I only put dependencies into a specific folder for yarn?

  2. 2

    How can I get a specific folder with a specific folders sibling in python

  3. 3

    How can I move specific files from within a folder when that folder is added to a directory?

  4. 4

    How can I tell if my columns are R1C1 reference style with excel vba?

  5. 5

    Using Powershell and Test-Path, how can I tell the difference between a "folder doesn't exist" and "access denied"

  6. 6

    How can I tell a function enters kernel or not

  7. 7

    How do I tell Pyinstaller to use an .EXE thats in the Scripts folder?

  8. 8

    How can I create a batch file to put file names in a .txt in a specific way

  9. 9

    Magento - How can I tell if I'm on a "My Account" page?

  10. 10

    How can I tell which user limit I am running into?

  11. 11

    How can I tell if I am out of inotify watches?

  12. 12

    How can I tell how many bits my ssh key is?

  13. 13

    How to set .NET Error Pages for a specific folder in IIS 7?

  14. 14

    Thunar - can I change the sorting method for one specific folder?

  15. 15

    How can I put Tolkeins Elvish in Java

  16. 16

    How can I put a "+" below each table?

  17. 17

    How can I programmatically tell if a filename matches a shell glob pattern?

  18. 18

    XMLEventWriter: how can I tell it to write empty elements?

  19. 19

    How can I tell Selenium to press cancel on a print popup?

  20. 20

    How can I tell Selenium to press cancel on a print popup?

  21. 21

    How can I tell which mysql user edited a table in mysql

  22. 22

    Ember: How can I tell if peekAll returns any models?

  23. 23

    How can I tell if my current PowerShell session is over SSH?

  24. 24

    How can I tell meson in which directories to look for dependencies?

  25. 25

    How can I tell if my vector matches the variable values in r?

  26. 26

    How can I tell through the Stripe API if a connected account is complete?

  27. 27

    How can I tell which web server Zimbra 8.0.6 is running?

  28. 28

    How can I tell whether a build is Debian-based?

  29. 29

    How can I tell Brunch not to concatenate javascript files?

ホットタグ

アーカイブ