Answer the question
In order to leave comments, you need to log in
Why does the RelatedObjectDoesNotExist error occur due to changes in the __init__ of the model when using admin.TabularInline?
Hello!
The question is, I want to change the choices of another depending on the value of one field of the model.
To do this, I override the __init__() method like this:
def __init__(self, *args, **kwargs):
super(MyModel, self).__init__(*args, **kwargs)
comp = self.composition #FOREIGN KEY
if comp.for_two:
self._meta.get_field_by_name('type')[0]._choices = self.COMP_MEMBER_TYPE_CHOICES_1
else:
self._meta.get_field_by_name('type')[0]._choices = self.COMP_MEMBER_TYPE_CHOICES
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question