开发者

Making only a part of model field available in Django

开发者 https://www.devze.com 2022-12-31 14:04 出处:网络
I have a such model: GENDER_CHOICES = ( (\'M\', \'Male\'), (\'F\', \'Female\') ) class Profile(models.Model):

I have a such model:

GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female') )
class Profile(models.Model):
    user = models.ForeignKey(User)
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)

class FrontPage(models.Model):
    female = models.ForeignKey(User,related_name="female")
    male = mod开发者_运维问答els.ForeignKey(User,related_name="male")

Once I attempt to add a new FrontPage object via the Admin page, I can select "Female" profiles for the male field of FrontPage, how can I restrict that?

Thanks


ForeignKey's limit_choices_to argument will allow you to limit the choices available via the admin interface.

0

精彩评论

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