Writing about Django orm models function definition file

models.py

 
 


Candidate class (BaseModel):
name = models.CharField (= 64 MAX_LENGTH,
the verbose_name = "name of the candidate",
null = True,
blank = True)
In Email = models.EmailField (null = True,
blank = True,
the verbose_name = "candidate the email address ")
code = models.CharField (= 48 MAX_LENGTH,
the verbose_name =" uuid table data corresponding to each ",
null = True,
blank = True)
on expire_time = models.DateTimeField (null = True,
the verbose_name = 'expiration' )

class Meta:
verbose_name = "候选人表"
verbose_name_plural = verbose_name

def __str__(self):
return self.name


class
InvitationJobInterviewForm (BaseModel): invite_people = models.ForeignKey(to='Employees', verbose_name = ' invitees ' , null=True, blank=True, related_name='invite_people_in_employees', on_delete=models.CASCADE) invited_people = models.ForeignKey(to='Candidate', verbose_name = ' invitees ' , null=True, blank=True, related_name='invited_people_in_candidate', on_delete=models.CASCADE) invite_people_code = models.CharField(max_length=64, verbose_name = " invitees code " , null=True, blank=True) jobs = models.ForeignKey(to='Jobs', verbose_name = " Jobs " , null=True, blank=True, on_delete=models.CASCADE, related_name='invite_people_jobs') class Meta: verbose_name = ' invited to job interviews Table ' verbose_name_plural = verbose_name @property def get_invite_people_name(self): try: self.invite_people.name except Exception: return 'null' return self.invite_people.name @property def get_invited_people_name(self): try: self.invited_people.name except Exception: return 'null' return self.invited_people.name @property def get_job_name(self): try: self.jobs.jobname except Exception: return 'null' return self.jobs.jobname def __str__(self): return self.invite_people_code

For example in a candidate table,

    def get_invited_people_name(self):
        try:
            self.invited_people.name
        except Exception:
            return 'null' return self.invited_people.name

self.invited_people across to a foreign key to another table self.invited_people.name across a table to get name (which is positive inquiry)
if the foreign key in another table, you can point directly to another the foreign key tables, so that tables can be present across the associated to that table, and then point to another name to get inside the table name (reverse lookup)

Guess you like

Origin www.cnblogs.com/tangda/p/12229355.html