0

I'm developing a hospital project!

People can apply online appointment for a specific doctor and the people will get a serial number once done the process of online appointment.

Here is my model:

class Appointment(models.Model):
    doctor = models.ForeignKey(
        DoctApp, on_delete=models.CASCADE, related_name="appointments")
    fee = models.IntegerField(default=1000, validators=[
                              MaxValueValidator(2000)])
    name = models.CharField(max_length=220)
    phone = models.CharField(max_length=12, default="01700000000")
    age = models.IntegerField(validators=[MaxValueValidator(200)])
    gender = models.CharField(max_length=10, choices=gen_choises)
    address = models.TextField(blank=True)
    created_at = models.DateTimeField(auto_now_add=True)
    pat_pic_date = models.DateField()
    serial_number  = models.IntegerField()


    def __str__(self) -> str:
        return f"""ID: {self.doctor.id} - {self.doctor.name} - Pat Name: {self.name}"""

Can you consider to share the auto-increment fields system to get serial the number fields?

1 Answers1

0

It sounds like you're looking for the primary key of the newly created appointment record. If so, you should be able to retrieve that with self.id

If you'd like to modify that number, here are some examples of how that could be done: https://stackoverflow.com/a/16753988/1536402

Ed Kohler
  • 534
  • 3
  • 9
  • It's similar but not the same! I need like 1,2,3,4... If some id = 3, id = 5, id = 6 . It's should be position one is id = 3, Position two is id = 5, Position three is id = 6 – MD Palash Babu Dec 12 '20 at 15:05
  • Got it. Here's an example of how to auto-increment a specific field, such as your serial_number field: https://stackoverflow.com/a/34872412/1536402 – Ed Kohler Dec 12 '20 at 15:22