bennylope / django-organizations

:couple: Multi-user accounts for Django projects

Home Page:http://django-organizations.readthedocs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Migration file does not include user field

juuisle opened this issue · comments

I tried this implementation as mentioned in the document's cookbook, but somehow the migration does not add a user field. I also added AUTH_USER_MODEL in the correct way. AUTH_USER_MODEL = 'core.UserAccount' (in my case)

class WareHouse(AbstractOrganization):

    y_tunus = models.CharField(_('y tunus'), max_length=15)

    class Meta(AbstractOrganization.Meta):
        abstract = False
        verbose_name = _('warehouse')
        verbose_name_plural = _('warehouses')


class WareHouseUser(AbstractOrganizationUser):

    class Meta(AbstractOrganizationUser.Meta):
        abstract = False
        verbose_name = _('warehouse user')
        verbose_name_plural = _('warehouse users')

    def __str__(self):
        return str(self.user)
    


class WareHouseManager(AbstractOrganizationOwner):

    class Meta(AbstractOrganizationOwner.Meta):
        abstract = False
        verbose_name = _('warehouse admin')
        verbose_name_plural = _('warehouse admins')

Because the migration does not include the user field, there're errors:

warehouse.WareHouseUser: (models.E012) 'unique_together' refers to the nonexistent field 'organization'.
warehouse.WareHouseUser: (models.E012) 'unique_together' refers to the nonexistent field 'user'.
warehouse.WareHouseUser: (models.E015) 'ordering' refers to the nonexistent field, related field, or lookup 'organization'.
warehouse.WareHouseUser: (models.E015) 'ordering' refers to the nonexistent field, related field, or lookup 'user'.
ERROR: 1

UPDATE: I found the specific issue, I need to add AbstractOrganizationInvitation to make it work. It seems like the code stop when it does not find AbstractOrganizationInvitation. The documentation is missing this, I think.

Suggest documentation change:

Advanced customization using abstract models
As of version 0.2.0 you can add your own fully customized models using unique table sets, i.e. single table inheritance. In order to do this, your app should define an organization model, an organization user model, an organization owner model, and an organization invitation model, each inheriting from one of the abstract models provided in organizations.abstract. Here’s an example from an accounts app:

from django.db import models
from organizations.abstract import (AbstractOrganization,
                                    AbstractOrganizationUser,
                                    AbstractOrganizationOwner,
                                     AbstractOrganizationInvitation)

class Account(AbstractOrganization):
    monthly_subscription = models.IntegerField(default=1000)

class AccountUser(AbstractOrganizationUser):
    user_type = models.CharField(max_length=1, default='')

class AccountOwner(AbstractOrganizationOwner):
    pass

class AccountInvitation(AbstractOrganizationInvitation):
    pass

Thanks a lot. This is not clear at all in the documentation and I lost quite a bit of time on this.

To be clear, this happened only on legacy objects when updating package from 1.1.2 to 2.2.0. When creating new objects, it worked fine.

Please fix it or add this solution in the migration documention.

Please fix it or add this solution in the migration documention.

@sebastien-powl PR's are welcome!