开发者

django: Admin interface for an extended class

开发者 https://www.devze.com 2023-02-08 10:45 出处:网络
I have two classes for which I want an admin interface. But one class extends the other. Ex class Questions(models.Model):

I have two classes for which I want an admin interface. But one class extends the other. Ex

class Questions(models.Model):
     p开发者_如何学JAVAass

class MathQuestion(Questions):
     some fields ....

Now the simplest way is to create a separate admin for MathQuestion. However, is there a possibility that I can have MathQuestion displayed in a more intuitive fashio in Admin, ex: When user goes to QuestionAdmin interface and selects a further type for Maths.


  1. Add extra field 'question_type' with default value of None and not nullable (so you can be sure Question can't have instances, not sure if it works)
  2. overload the save method in child class and assign there some value to question_type, meaning MathQuestion.
  3. Use filtering in admin as always.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号