开发者

What type of inheritance allows this

I have 2 simple models; a "JobInfo" model and a "Contact" model.

class JobInfo(models.Model):
    client = models.Ch开发者_运维知识库arField(max_length=50, choices=CLIENT_CHOICES)
    job_number = models.CharField(max_length=30, unique=True, blank=True, null=True)
    page_type = models.CharField(max_length=50, choices=PT_CHOICES)
    contact = models.CharField(max_length=50, choices=CONTACT_CHOICES?)

    def __unicode__ (self):
    return self.job_number

    class Admin: 
        pass

class Contact(models.Model):
    name = models.CharField(max_length=64, unique=False, blank=True, null=True)
    position = models.CharField(max_length=50, choices=CLIENT_CHOICES)
    phone = models.CharField(max_length=15, unique=False, blank=True, null=True)
    fax = models.CharField(max_length=15, unique=False, blank=True, null=True)
    email = models.EmailField()

    def __unicode__ (self):
    return self.name

    class Admin: 
        pass

Can my "Contact" objects (from Contact Model) be choices for the contact field in the "JobInfo" model? I'd like to be able to select contacts in my JobInfo form and have those Contact properties available to display in the same template.


You want to create a relationship, right?

So the contact field on your JobInfo model should look like this:

contact = models.ForeignKey('Contact')


could you try

class JobInfo(models.Model):
    ...
    contact = Contact(models.Model)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜