0
votes

how do i get the firstname and lastname in api in wagtail??

there is one form in the page..when I add firstname and lastname in form then it should display in api in front end

firstname and lastname should display in api front end

how to do this??

form/models.py

from django.db import models

# Create your models here.
from django.db import models
from modelcluster.fields import ParentalKey
from wagtail.admin.edit_handlers import (
    FieldPanel, FieldRowPanel,
    InlinePanel, MultiFieldPanel
)
from wagtail.core.fields import RichTextField
from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField
from wagtail.api import APIField
from django import forms
from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db import models
from django.shortcuts import render
from modelcluster.fields import ParentalKey, ParentalManyToManyField
from modelcluster.contrib.taggit import ClusterTaggableManager
from rest_framework.fields import Field
from taggit.models import TaggedItemBase
from wagtail.api import APIField




class FormField(AbstractFormField):
    page = ParentalKey('FormPage', on_delete=models.CASCADE, related_name='form_fields')


class FormPage(AbstractEmailForm):

    
    def get_api_representation(self, value,context=None):
        return "anything"
    
    template = "form.html"


    content_panels = AbstractEmailForm.content_panels + [
        InlinePanel('form_fields', label="Form fields"),
    ]

    @property
    def form_fields(self):
        return self.form.fields

    api_fields = [
        # This is using a custom django rest framework serializer
        APIField("form_fields"),
    ]
It would be good to add some code for your existing page model, including the current definition for api_fields as per docs.wagtail.io/en/stable/advanced_topics/api/v2/…LB Ben Johnston
i want like a form ..In that form firstname and lastname should be there when i submit data it should display in front end apiRanjitha Sanker
Are you building a headless version of Wagtail? When you say API are you hoping to read the form submission data from the FormPage API Result or did you want to set up a new endpoint for a submission result?LB Ben Johnston
i want to display all employees first name and last name in wagtail api using formRanjitha Sanker