Похожие чаты

In a Django project am working on, I need to

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/

9 ответов

8 просмотров

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.

ᶰᵃᵇʳᵒˡᵉᵒᶰ- Автор вопроса
Gian
You can create permissions that allow users to do ...

Yes I can but how can I keep track which resellers are under which owners?

ᶰᵃᵇʳᵒˡᵉᵒᶰ- Автор вопроса
Gian
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

ᶰᵃᵇʳᵒˡᵉᵒᶰ
Yeah I got that, what I wanted to say is, I wanted...

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)

ᶰᵃᵇʳᵒˡᵉᵒᶰ- Автор вопроса
Gian
Well, both reseller and owner are users, no? So, y...

Both Owner and Reseller are users, The superuser add owners and Owners can add multiple resellers

ᶰᵃᵇʳᵒˡᵉᵒᶰ
Both Owner and Reseller are users, The superuser...

Yeah, one to many, as a I said. And you want to cascade that when you delete a owner, it removes all resellers

Похожие вопросы

Обсуждают сегодня

Какой-то там пердун в 90-х решил, что есть какая-то разная типизация. Кого вообще это волнует?
КТ315
49
Hi. Do we have a raid bot? Why nobody doing raids on X? Even RH mentioned this and nobody paying attention...whats the channel for hex memes? If mods cant run raids just insta...
H
31
Подскажите, а есть vault lite или ченить такое?) А то нужен вольт для похода в вольт, но весит он ~500 мб) как-то многовато для парочки запросов ))
Alexandr Orloff
17
блеать, почему так?? где в роутере это исправляется?
Арсен Маньяков 🇦🇲
16
void terminal_scroll() { memmove(terminal_buffer, terminal_buffer + VGA_WIDTH, buffer_size - VGA_WIDTH); memset(terminal_buffer + buffer_size - VGA_WIDTH, 0, VGA_WIDTH); ...
Егор
47
🌊 Ocean Nodes Dashboard Update 🚀 Hey, Oceaners! First off, a massive round of applause 👏to all of you for the amazing engagement since we launched Ocean Nodes. In just a few ...
KreigDK | Never DM first🌊
3
Всем привет! Подскажите, пожалуйста, в чем ошибка? Настраиваю подключение к MySQL. Либы лежат рядом с exe. Все как по "учебнику"
Евгений
16
А можете как-то проверить меня по знаниям по ассемблеру?
A A
132
Здравствуйте! У меня появилась возможность купить книгу "Изучай Haskell во имя добра!". Но я где-то слышал, что эта книга устарела. Насколько это правда??
E
22
люди, которые используют flameshot, к вам вопрос. Можно-ли поставить хоткей на создание скриншота? В программе есть отдел "горячие клавиши", но там все для редактирования, скр...
ThunDer104
11
Карта сайта