Before adding a person in a event, I would like to search it.
- If the person exists, add it.
- If not, create it and add it.
I have tried many times with different ways in admin.py
, but I am not able to get it.
Could someone help me with the admin.py
?
models.py
class Person (models.Model):
dni= models.CharField(primary_key = True, max_length=9 )
name= models.CharField(max_length = 30)
surname1 = models.CharField(max_length = 30)
surname2 = models.CharField(max_length = 30)
table = models.PositiveIntegerField(default=0)
def __str__(self):
return self.dni
class Meta:
ordering = ('dni',)
class Event (models.Model):
name = models.CharField(max_length = 100)
people= models.ManyToManyField(Person,blank = True, default = None)
date = models.DateField('date event')
category = models.CharField (choices = TYPE_EVENT, max_length = 1)
def __str__(self):
return self.name
class Meta:
ordering = ('name',)
Currently all persons appear in the box. But its not correct.
I would like to get something like this (link) but I didn't get the solution :S.