I want to deal the m2m relationship in django admin site.I customized the inline class,modified the form and formset .But nothing is changed,and no mistake happen. I see the django website release notes,which said has fixed inline form bug.I do know how to do . this is my model.py #coding=utf-8 # Create your models here.
from django.db import models from django.contrib import admin from django import forms from django.forms.models import inlineformset_factory from django.forms import ModelForm class totattrib(models.Model): name=models.CharField(max_length=30,unique=True) description=models.CharField(max_length=60,blank=True) def __unicode__(self): return self.name class subattrib(models.Model): name=models.ForeignKey(totattrib) subname=models.CharField(max_length=30,unique=True) description=models.CharField(max_length=60,blank=True) def __unicode__(self): return self.subname class resources(models.Model): name = models.CharField(max_length=60,unique=True) urls = models.URLField() startingdate = models.DateField(auto_now_add=True) endingdate = models.DateField(blank=True,null=True) published_choices = ( ('y', 'yes'), ('n', 'no'), ) published = models.CharField(max_length=2, choices=published_choices) usages = models.URLField(blank=True) attribs = models.ManyToManyField(subattrib, through='resourcehash') def show_sub(value): objects = value.attribs.all().order_by("id") str='<table style="border:none;"><tr>' for obj in objects: str += '<td style="border:none;">'+obj.subname+'</td>' str+='</tr></table>' return str show_sub.allow_tags=True def __unicode__(self): return self.name class resourcehash(models.Model): resource=models.ForeignKey(resources) attrib=models.ForeignKey(subattrib) def __unicode__(self): return self.resource.name + " " + self.attrib.subname class resourcesadminform(forms.ModelForm): class Meta: model = subattrib fields=('subname',) class resourceadminform(forms.ModelForm): class Meta: model = resourcehash fields = ('id','resource', 'attrib') resourceFormSet = inlineformset_factory(resources, resourcehash, fk_name="resource",form=resourceadminform, can_delete=False) this is admin.py #coding=utf-8 #!/usr/bin/env python from django.contrib import admin from django import forms from lib.esource.models import resources,totattrib,subattrib,resourcehash,resourcesadminform,resourceadminform,resourceFormSet class resourcehashInline(admin.TabularInline): model=resourcehash formset=resourceFormSet form=resourcesadminform # template="admin/esource/resources/inline.html" extra=1 class resourcesAdmin(admin.ModelAdmin): inlines = (resourcehashInline,) list_display= ('name','urls','startingdate','endingdate','published','show_sub') list_filter=('attribs','published') search_fields=('name',) admin.site.register(resources, resourcesAdmin) class subattribAdmin(admin.ModelAdmin): list_select_related=True list_display=('name','subname','description') list_display_links=('subname',) list_filter=('name',) # inlines = (resourcehashInline,) admin.site.register(subattrib, subattribAdmin) class totattribAdmin(admin.ModelAdmin): list_display=('name','description') admin.site.register(totattrib,totattribAdmin) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---