On Feb 14, 9:30 am, john <johncarl...@hailmail.net> wrote:
> Hi, I just had fun creating a new Custom Admin Form to sort a
> ManyToMany field by ABC order (why isnt it in ABC order by default on
> the "def __unicode__" item?)  It works great, but now the Green Plus
> Sign to add more items to the list is missing, where did it go?  I
> guess its not enabled by default?
>
> Does anyone know where I can search on this more, and/or what this
> Green Plus Sign is called?  Is this just an extra command that needs
> to be entered or do I have to reinvent the wheel to get this back to
> working?
>
> thanks!
>
> This is the Green Plus Sign im looking for (even though this is for a
> ForeignKey field):http://docs.djangoproject.com/en/dev/_images/admin10.png
>
> My code if you want to take a look (sorry that a lot of it has to be
> redacted):
>
> # more xyz/admin.py
> from abc.xyz.models import Items,Stuff
> from django.contrib import admin
> from django import forms
>
> class StuffForm(forms.ModelForm):
>
> item=forms.ModelMultipleChoiceField(queryset=Items.objects.order_by('item'))
>
>         class Meta:
>                 model=Stuff
>
> class StuffAdmin(admin.ModelAdmin):
>         exclude=('items',)
>         form=StuffForm
>
> admin.site.register(Stuff, StuffAdmin)
>
> # more xyz/models.py
> class Items(models.Model):
>         item=models.CharField(max_length=100)
>
>         def __unicode__(self):
>                 return self.item
>
> class Stuff(models.Model):
>         items=models.ManyToManyField(Items)

I found it rather hard to follow your code, but I think the problem
might be that you haven't registered the object that is missing the
'green plus sign' with the admin.  Without it, you cannot create new
objects of that type. You can access existing objects from other
models, however, which provides the behaviour you describe.

Matt.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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