I have two models first User model and second Organization Model.
Admin will be responsible for adding data in Organization Model.So I have used Foreign key.
class Organizaton(models.Model):
name = models.CharField(max_length=255)
status = models.BooleanField(default=True)
created_by = models.ForeignKey(CustomUser,on_delete=models.CASCADE,limit_choices_to= {'is_staff': True})
created_date = models.DateTimeField(auto_now_add=True)
and I have a Custom User table where I want to store which user belongs to which Organization:
class CustomUser(AbstractUser):
organization_name = models.ForeignKey(Organization,on_delete = models.CASCADE)
If I declare CustomUser Class first, then there is an error inside
CustomUser class in organization_name field that says class Organization is not Found or declared
.
If I declare Organization Model class before CustomUser model class, then I'm getting an error inside the Organization class in created_by field saying CustomUser class not found or declared
.
How can I solve this issue?
question from:
https://stackoverflow.com/questions/65880812/how-to-create-choice-field-in-django-model-using-another-model 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…