4

I have a problem concerning Django inlines within the admin interface. I have two classes: List and ListElement defined as follows:

class List(models.Model):
    pass

class ListElement(models.Model):
    text = models.CharField(max_length = 64)
    parent = models.ForeignKey(List, related_name = 'elements')

The admin view is:

class ListElementInline(admin.TabularInline):
    model = ListElement
    extra = 3

class ListForm(forms.ModelForm):
    default_text = forms.CharField(max_length = 64)
    class Meta:
        model = List

class ListAdmin(admin.ModelAdmin):
    form = ListForm
    inlines = [ListElementInline]

Since I am lazy, I would like to have a List-level field which I could fill with a "default" value and before the whole thing is saved this default value would be inserted into all ListElements that were left blank.

The major problem that I have encountered is the fact that this should be done during the validation step, when the data is not yet cleaned. Also, I know that is is possible to communicate between the inline form and the whole inline formset (link), but I couldn't find any information how to connect the modelform (ListAdmin) and the formset (ListElementInline) that is inlined within it.

Thanks for any advice.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.