Saturday, March 30, 2013

Filtering M2M in Admin Interface

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

--
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