How to store data in model which contain foreign key in Django
models.py
class event_details(models.Model):
e_id = models.AutoField(primary_key= True)
class participants(models.Model):
p_id = models.AutoField(primary_key= True)
p_name = models.CharField(max_length=30)
def __str__(self):
return str(self.p_id)
class event(models.Model):
e_id = models.ForeignKey(event_details,on_delete = models.CASCADE, related_name = 'event_id')
p_id = models.ForeignKey(participants, on_delete=models.CASCADE, related_name = 'pp_id')
view.py
def add_user(request):
if request.method == 'POST':
name =request.POST.get('name')
reg = participants(
e_id = 1,
p_name = name,
)
reg.save()
return render(request,'web/Registration.html')
Try to Store Participate name But Error that "participants.e_id" must be a "event_details" instance. can help me to solve it by store data in participants model