Friday, April 8, 2022

Re: NameError:

Hi! In the line where the error occurs, Pharmacist has not been defined yet. Move your Pharmacist model before your Patients model.

Regards,

Antonis


On 08/04/2022 20.49, tech george wrote:

Hello,

I've been struggling with the below error, what might be the problem?

I have used the same ForeignKey in other models.. all works ok, except this.

Please advise.

Models:

class CustomUser(AbstractUser):
    user_type_data = ((1, "AdminHOD"), (2, "Pharmacist"), (3, "Doctor"), (4, "PharmacyClerk"),(5, "Patients"))
    user_type = models.CharField(default=1, choices=user_type_data, max_length=10)



class Patients(models.Model):
    gender_category=(
        ('Male','Male'),
        ('Female','Female'),
    )

    nurse = models.ForeignKey(Pharmacist, related_name='Pharmacist', on_delete=models.CASCADE, null=True)
    admin = models.OneToOneField(CustomUser,null=True, on_delete = models.CASCADE)
    reg_no=models.CharField(max_length=30,null=True,blank=True,unique=True)
    gender=models.CharField(max_length=7,null=True,blank=True,choices=gender_category)
    first_name=models.CharField(max_length=20,null=True,blank=True)
    last_name=models.CharField(max_length=20,null=True,blank=True)
    date_admitted=models.DateTimeField(auto_now_add=True, auto_now=False)
    last_updated = models.DateTimeField(auto_now_add=False, auto_now=True)

    def __str__(self):
        return str(self.admin)


Error:

nurse = models.ForeignKey(Pharmacist, related_name='Pharmacist', on_delete=models.CASCADE, null=True)
NameError: name 'Pharmacist' is not defined


Regards,




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADYG20GbMnoGjkT7VtD1FFMw3Tr8Axaepnf27vDyvqYvMb%2BUiQ%40mail.gmail.com.

No comments:

Post a Comment