Hm... I asked a question similar to this, but no one responded :(
But I think I over complicated the problem. Maybe I'll try simpler way.

Suppose I have two models:

1) default Django user model
2) a simple custom model like this:
class RegistrationQueue(models.Model):
    user = models.ForeignKey(User)
    token = models.CharField(max_length=40)
    status = models.CharField(max_length=10)

so in the admn.py I have:

RegistrationAddForm(models.ModelForm):
    class Meta:
        model = User

RegistrationListForm(models.ModelForm):
    class Meta:
        model = RegistrationQueue

what I would like to do is to use RegistrationAddForm when adding another
RegistrationQueue record, but use RegistrationListForm to list them. To do
this, I've tried something like this:

class RegistrationQueueAdmin(admin.ModelAdmin):
    add_form = RegistrationAddForm
    view_form = RegistrationViewForm

    def get_form(self, request, obj=None, **kwargs):
        defaults = {}
        if obj is None:
            defaults.update({
                'form': self.add_form,
            })
        else:
            defaults.update({
                'form': self.view_form
            })
        defaults.update(kwargs)
        return super(RegistrationQueueAdmin, self).get_form(request, obj,
**defaults)
admin.site.register(RegistrationQueue, RegistrationQueueAdmin)

I hoped this would alternate between add_form and view_form when adding,
viewing, respectively. But it only wants to use RegistrationViewForm. It
never displays RegistrationAddForm.

Should I be subclassing add_view, change_view, etc. methods instead of
get_form?

Please Please help me. Thank you!

Eiji

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

Reply via email to