Hi everyone, I am new using Django and I am trying to build a project that requires to use a Custom User Model. I have encountered many problems on my way, tried to resolve them on my own but after more than one week I am exhausted, so I ask for your help.
I think the main problem is that I don’t understand well how to create a CustomUser model. I need a user to have many fields (E.g full_name, mobile_phone, etc), but one of the critical fields which I’ve had problems is: division_id (wich is a foreign key for a model created in another app named ‘divisions’). I’ve had a lot of problems because there is no any migration yet (its supposed that your first migration must be when you created your custom user model), so there isn’t any values in ‘division’ model. Is it possible to refer a foreign key in that case considering that the model referred isn’t created yet? I mean, the first migration can create a custom user model and a division model simultaneusly, or what I have to do?
Another problem I have, is that when I’m trying to refer the Division model into my CustomUser model, I have errors. I use relative import but it returns ‘attempted relative import beyond top-level package’
(I know what it means, but for me, my relative path is OK, I don’t understand why it doesn’t work).
This is my relative path: from …divisions.models import Division
This is my project structure:
I am trying to reference the model Division (which inside divisions.models) from my CustomUser model (which is inside users.models). I read that a ‘.’ means ‘from the same folder, import…’ so I used ‘…’ because the Division model is in another folder, but didn’t work. Hope you can help me please