Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom related_name between Organization, OrganizationOwner, and OrganizationUser #186

Open
n8sty opened this issue Nov 15, 2019 · 2 comments
Labels

Comments

@n8sty
Copy link

n8sty commented Nov 15, 2019

I'm trying to add django-organizations to a nascent project and it looks like it should do nearly exactly what I want except for one thing. I'm using a sub-classed OrganizationUser model from OrganizationUserBase. The relation between the org, owner, and user in the database is specified in terms of organization_id, and organization_user_id regardless of the name of my subclassed objects and regardless of what I put for default_related_name in model meta. I poked around this projects code and it looks like there are a few places that might rely on explicitly having these relationships named like this - I'm wondering how necessary is this? Is it something that could be changed? If I manually foreign key my models together using a different name than the one provided how much functionality will break?

Example:

class Lab(OrganizationBase, TimestampBase, UUIDBase):
    name = models.CharField(max_length=255, help_text=_("What is the lab's name?"))

    class Meta(TimestampBase.Meta):
        db_table = "lab"
        default_related_name = "lab"
        verbose_name = _("lab")
        verbose_name_plural = _("labs")


class LabUser(OrganizationUserBase, TimestampBase, UUIDBase):
    email = models.EmailField(
        blank=True, default="", help_text=_("What is the user's email address?")
    )

    class Meta(TimestampBase.Meta):
        db_table = "lab_user"
        default_related_name = "lab_user"
        verbose_name = _("lab user")
        verbose_name_plural = _("lab users")


class LabOwner(OrganizationOwnerBase, TimestampBase, UUIDBase):
    
    class Meta(TimestampBase.Meta):
        db_table = "lab_owner"
        default_related_name = "lab_owner"
        verbose_name = _("lab owner")

results in a database schema where lab_owner has a foreign key named organization_id and organization_user_id.

This isn't a deal breaker, but it makes it more difficult to use the database directly because my app doesn't embrace the concept of organizations.

@bennylope
Copy link
Owner

I poked around this projects code and it looks like there are a few places that might rely on explicitly having these relationships named like this - I'm wondering how necessary is this?

Strictly speaking, I don't think it's absolutely necessary. We'd just need to be able to introspect the related name.

Is it something that could be changed?

Yes, I do think so. And provided it was not backwards incompatible it would be a welcome addition. Is it something you'd have interest in writing a PR for?

@n8sty
Copy link
Author

n8sty commented Dec 23, 2019

Yes, I do think so. And provided it was not backwards incompatible it would be a welcome addition. Is it something you'd have interest in writing a PR for?

Very much so. I haven't had a chance to make material process on the project that would require this change but I should be (re-)beginning work soon and assuming that this is still useful to me I'll take a crack at making the above change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants