On Mon, Sep 22, 2008 at 12:49 PM, Jason <[EMAIL PROTECTED]> wrote:

>
> Thanks for the reply Karen.
>
> With that being said I would still like to know just how easy or hard
> it is to switch something like this around. In real terms its only a
> minor change. Can this be achieved with a few lines in my admin.py
> file or would I have to do this another way?
>

It's easy enough to override the form used by Admin, and then its just a
matter of creating the form to meet your specifications.  Given a model
defined as:

class Category(models.Model):
    title = models.CharField(max_length=40)
    parent = models.CharField(max_length=40, null=True, blank=True)

You could put this in your admin.py:

class MyCategoryForm(forms.ModelForm):
    parent = forms.ChoiceField(required=False)
    class Meta:
        model = Category
    def __init__(self, *args, **kwargs):
        super(MyCategoryForm, self).__init__(*args, **kwargs)
        self.fields['parent'].choices = [('', '-----')]
        self.fields['parent'].choices.extend([(c.title, c.title) for c in
Category.objects.all()])

class CategoryAdmin(admin.ModelAdmin):
    form = MyCategoryForm
    class Meta:
        model = Category

admin.site.register(Category, CategoryAdmin)

----

which I think would give what you ask for.

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to