views:

11

answers:

0

Suppose I have a model Animal. Animals have a field species which can either be "Lion" or "Dolphin".

The AnimalAdmin should have two views, add_lion_view() and add_dolphin_view(), which call the standard add_view() method after making sure that either species is going to be added.

I used to do this by setting the an AnimalAdmin instance's variable _adding_species = "Dolphin|Lion" in the respective add_*_view() methods.

The get_form() method would then return the LionForm or DolphinForm, according to the _adding_species var.

However, this is buggy code since the AnimalAdmin instance is used by many requests – thus different views setting the same variable are interfering with each other. I need to somehow pass along an adding_species param.

What would be the best design?

Some thoughts:

  • I do not want to rewrite the standard add_view().
  • Adding adding_species variable to request object? Seems messy?
  • or, how can the admin's get_form() tell which add_*_view was requested? Do I need to parse the URL again?

Thank you.