Sunday, March 31, 2013

Re: Filtering M2M in Admin Interface

Answering myself, but for future searchers.
This is related to this bug report
https://code.djangoproject.com/ticket/14891 as well as this
discussion http://goo.gl/ac5lg
So for now I'll figure out a work around with QuerySets and indexes,
instead of using keys.

Cheers,
Tim

On Sat, Mar 30, 2013 at 1:40 PM, Tim Cook <tim@mlhim.org> wrote:
> Hi All,
>
> I have a scenario setup very much like the Polls example in the tutorial.
>
> class Terminology(models.Model):
> name = models.CharField(max_length=110)
> abbreviation = models.CharField(max_length=20)
> version = models.CharField(max_length=30)
>
> def __unicode__(self):
> return self.name + " : " + self.version
>
> class Codes(models.Model):
> terminology = models.ForeignKey(Terminology)
> code_string = models.CharField(max_length=110)
> code = models.CharField(max_length=20)
> url = models.URLField(verbose_name="Reference", help_text="An
> optional reference to the description for the code.", blank=True)
>
> def __unicode__(self):
> return self.code + " : " + self.code_string
>
>
> Now to extend this a bit.
>
> class DvCodedString(DvString):
> terminology = models.ForeignKey(Terminology, null=True, blank=True)
> codes = models.ManyToManyField(Codes, null=True, blank=True)
> ...
>
>
> My admin models:
> class CodesInline(admin.TabularInline):
> model = Codes
> extra = 5
>
> class TerminologyAdmin(admin.ModelAdmin):
> fieldsets = (
> (None, {'classes':('wide',),
> 'fields':('abbreviation','version','name',)}),
> )
> inlines = [CodesInline]
> admin.site.register(Terminology, TerminologyAdmin)
>
>
> class DvCodedStringAdmin(admin.ModelAdmin):
> fieldsets = (
> (None, {'classes':('wide',),
> 'fields':('published','prj_name','data_name',)}),
> ("Basic", {'classes':('collapse',),
> 'fields':('terminology','codes',),
> 'description':'When all codes come from one
> terminology (and one version of it).'}),
>
> ...
>
> Currently all codes will be shown in the select box.
> But of course what I really want is the Terminology Choice to filter
> the available codes displayed.
>
> So, my question is:
> Where can I find the relevant documentation on doing this in the admin
> interface?
> Or can it be done in the admin interface?
>
> Thanks,
> Tim
>
>
>
>
>
> --
> ============================================
> Timothy Cook, MSc +55 21 94711995
> MLHIM http://www.mlhim.org
> Like Us on FB: https://www.facebook.com/mlhim2
> Circle us on G+: http://goo.gl/44EV5
> Google Scholar: http://goo.gl/MMZ1o
> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook



--
============================================
Timothy Cook, MSc +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment