Django populate select field based on model query

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-04-26T14:57:29Z Indexed on 2010/04/26 15:13 UTC
Read the original article Hit count: 183

Filed under:

I have the following model

class DNS(models.Model):
    domain = models.ForeignKey(Domain)
    host_start = models.CharField(max_length=150, blank=True, null=True)
    type = models.SmallIntegerField(max_length=1, default=0, choices=DNS_CHOICE)
    value = models.SmallIntegerField(max_length=3, default=0, blank=True, null=True)
    ip = models.IPAddressField(blank=True, null=True)
    host_end = models.ForeignKey("DNS", blank=True, null=True)
    other_end = HostnameField(max_length=150, blank=True, null=True)
    created = models.DateTimeField(auto_now_add=True)
    sticky = models.BooleanField(default=0)
    other = models.BooleanField(default=0)

When I try to init a form with just foreignkeys on host_end.. it always shows all entries in the DNS table

domain = Domain.objects.get(id=request.GET['domain'], user=request.user, active=1)
form = DNSFormCNAME(initial={'ip': settings.MAIN_IP, 'type': request.GET['type'], 'host_end': DNS.objects.filter(domain=domain)})

I just want the zones that match that domain.. not all domains.

© Stack Overflow or respective owner

Related posts about django