On Sep 22, 10:16 pm, Nicolas Steinmetz <nsteinm...@gmail.com> wrote:
> Hello,
>
> I would like to present only a subset of a given models. But so far,
> in the admin, I have no value whereas there should be some.
>
> I tried several syntax but did not find the right one.
>
> Here are my implicated (and simplified) models :
>
> class Dns(models.Model):
>     """
>     DNS description
>     """
>     TYPEDNS_CHOICES = (
>         ('1', 'Reference'),
>         ('2', 'Normal'),
>     )
>     name = models.CharField(blank=True, max_length=100)
>     dnstype = models.CharField(max_length=100,
> choices=TYPEDNS_CHOICES)
>
> class Url(models.Model):
>     """
>     Url description
>     """
>     name = models.CharField(blank=True, max_length=100)
>     [...]
>     cnamevalue = models.ForeignKey(Dns, limit_choices_to = {'dns':
> 'get_sql(Dns.dnstype="2")'}, blank=True)
>
> Could someone explain me what is the right syntax ?
>
> I could use formfield_for_foreignkey for admin contrib but I would
> prefer using limit_choices_to that I see as a native solution.
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri...
>
> Thanks,
> Nicolas

Seems like you're looking at the ForeignKey documentation. The
reference to get_sql() is confusing and very out of date on that page
- Q objects don't have such a method, although they may have done back
before the merge of queryset-refactor before version 1.0 was released.

Anyway, the syntax is simple:
    limit_choices_to = {'dnstype': 2}
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to