Hello Users,
Hoping for someone to help me with this, I have a admin form which I am
overwriting as below:
admin.py
def add_related_field_wrapper(form, col_name):
rel_model = form.Meta.model
rel = rel_model._meta.get_field(col_name).rel
form.fields[col_name].widget = RelatedFieldWidgetWrapper(
form.fields[col_name].widget,
rel,
admin.site,
can_add_related=True,
can_change_related=True
)
class DocumentItemsForm(forms.ModelForm):
tags = ModelMultipleChoiceField(label="Tags", required=False, queryset=
Terms.objects.filter(termtypeid__name='tag'))
categorys = ModelMultipleChoiceField(label="Categorys", required=False,
queryset=Terms.objects.filter(termtypeid__name='category'))
def __init__(self, *args, **kwargs):
super(DocumentItemsForm, self).__init__(*args, **kwargs)
add_related_field_wrapper(self, 'tags')
@admin.register(Documentitems)
class DocumentitemsAdmin(admin.ModelAdmin):
form = DocumentItemsForm
save_as = True
I get the below exception:
Django Version: 2.1.7
Exception Type: FieldDoesNotExist
Exception Value: Documentitems has no field named 'tags'
The actual model does not have those fields above, I have a feeling its
looking up the actual model which is why its not finding the field. In
essence what im trying to do is add a custom field that does not exist in
the model which works fine, however i need to be able to add the plus
button next to the field which allows the user to add a new record and ive
be lead to the above solution to achieve this.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/1950c6dd-3fa7-4cea-a5c5-4b87c68c4300%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.