have 2 user types. One is an Owner and the other is a Reseller
The superuser creates owners, and the owners create resellers under them. I want to keep track of which Resellers are registered under which Owner by connecting Owners and Resellers table via a Foreign Key. So no reseller can create an account by themselves, their owners should do that for them. How can I accomplish this?
you can find what I have tried so far in the link below
https://www.reddit.com/r/django/comments/rd9o9u/how_to_let_one_type_of_users_create_another_type/
There are several ways to accomplish this. But the most "Django" way would be using the permissions system.
Can you expand on that a little?
You can create permissions that allow users to do some action, and then you assign those permissions to either the user directly, or a group.
Yes I can but how can I keep track which resellers are under which owners?
Oh, that'd be using Django ORM, of course.
Yeah I got that, what I wanted to say is, I wanted to is that, I was trying to connect the Owner model and the Reseller like this using foreign key, class Reseller(models.Model): user = models.ForeignKey(Owner, on_delete=models.CASCADE) but It don't seem to do the job, I still can't know which reseller is under which owner, I was hoping if you could shed some light on that
Well, both reseller and owner are users, no? So, you make both have a user as foreignkey. But, you also make a one to many relationship between the owner and the reseller (I"m assuming a owner can "own" multiple resellers)
Both Owner and Reseller are users, The superuser add owners and Owners can add multiple resellers
Yeah, one to many, as a I said. And you want to cascade that when you delete a owner, it removes all resellers
Обсуждают сегодня