I am new to programming and currently learning Django. I am working on a web application where users can register new pigeons into a database. The registration form includes fields for the pigeon’s name and a long dropdown menu with all the existing records for the father and the mother, which becomes quite tedious with many pigeons. Is there a strategy to solve this? Something like search fields to allow the user to search and select the father and the mother? And if parents do not exist, to add functionality to register them from there, similar to the admin form?
If the father or mother doesn’t exist in the database, the user should be able to create a new parent record directly from the main registration form without leaving the page.
I have implemented the following model for the Pigeon
:
`python
from django.db import models
class Pigeon(models.Model):
GENDER_CHOICES = (
(‘male’, ‘Male’),
(‘female’, ‘Female’),
)
name = models.CharField(max_length=100)
gender = models.CharField(max_length=10, choices=GENDER_CHOICES)
father = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, related_name='children_set')
mother = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, related_name='children_set')
def __str__(self):
return self.name
`
I’m facing an issue where I can’t seem to create new parent records from the main registration form. Could someone please help me understand what I’m doing wrong and provide guidance on how to implement this functionality correctly?
I would really appreciate any help or advice you can offer. I’m still learning, and this project is helping me improve my Django skills.
Thank you in advance!
Help from experts.
Thanks
Rafael Maura is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.