Hello,
I have a problem with custom User model. Maybe take a look into my code and then everything will be clear:
my_app_only_for_Users_&_Groups.models.py:
class User(AbstractUser):
phonenumber= models.PositiveIntegerField(blank=True, null=True)
settings.py:
AUTH_USER_MODEL = 'my_app_only_for_Users_&_Groups.User'
my_other_app.models.py:
from django.conf import settings
class ProductionCheck(models.Model):
many_fields....
created_by= models.ForeignKey(settings.AUTH_USER_MODEL,
on_delete=models.SET_NULL,
null=True)
The problem is that after save() new object I have blank cell in my datebase When I try to check- print(settings.AUTH_USER_MODEL) the current user in views.py I only see in console the string which I assigned to AUTH_USER_MODEL so in my case my_app_only_for_Users_&_Groups.User.
I would like to ask for explaination of this situation. After check many tutorials, with the same code I hope that I will get in my database’s cell something like string of User who created the object or its ID.
Using the ForeingKey in models.py is not enouth to achieve my expectation?
Should I use everytime something like that in my views.py:
def form_valid(self, form):
form.instance.created_by= self.request.user