Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8290451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:49:07+00:00 2026-06-08T12:49:07+00:00

I have a project whereby am trying to regroup some fields where some will

  • 0

I have a project whereby am trying to regroup some fields where some will be visisble and others will be displayed in a form so i can apply java script on the fields to expand. Can any one advise me how can i do such thing both in my modelForm class and template strcuture?

models.py

class Page(models.Model):
    # version control columns
    version_from = models.DateTimeField(auto_now_add=True, editable=False)
    version_to = models.DateTimeField(null=True, blank=True, editable=False)
    # data
    name = models.CharField(_('Name'), max_length=10, help_text=_('The name of the page will be used as a display name & in navigation menus'))
    show_in_navigation = models.BooleanField(default=True)
    slug = models.SlugField(_('Slug'), )
    subject = models.CharField(_('Subject'), max_length=30, )
    html_title = models.CharField(_('HTML Title'), max_length=15, blank=True, null=True)
    keywords = models.CharField(_('HTML Keywords'), max_length=200, blank=True, null=True)
    content = models.TextField(_('Content'), )
    parent = models.ForeignKey('self', null=True, blank=True)
    # audit
    created_at = models.DateTimeField(auto_now_add=True)
    created_by = models.ForeignKey(User, editable=False)

    # objects manager
    objects = PageManager()

    class Meta:
        unique_together = (
            'id',
            'slug'
        )

forms.py

class PageForm(forms.ModelForm):
    class Meta:
        model = Page

page-form.html

    <form class="form well" method="POST">
        {% csrf_token %}
            {% if form.errors %}
            <div class="alert alert-error">
                <a class="close" data-dismiss="alert" href="add_blog.html#">&times;</a>
                <h3>Error</h3>
                {{ form.non_field_errors }}
                {% for field in form %}
                        {{ field.errors }}
                {% endfor %}
            </div>
            {%endif%}

            {% csrf_token %}

            {# Include the hidden fields #}
            {% for hidden in form.hidden_fields %}
                {{ hidden }}
            {% endfor %}

            {# Include the visible fields #}
            {% for field in form.visible_fields %}

                    {{ field.label_tag }} {{ field }}
                    <span class="help-block">{{ field.help_text }}</span>

            {% endfor %}
        <br />
        <input type="submit" value='{% trans 'Login' %}' class="btn" />
    </form>

my challenge is, how can i make the fields slug and keywords render in the html in a div tag and at the end.

below is example to what i wish to achieve

    <form class="form well" method="POST">
        {% csrf_token %}
            {% if form.errors %}
            <div class="alert alert-error">
                <a class="close" data-dismiss="alert" href="add_blog.html#">&times;</a>
                <h3>Error</h3>
                {{ form.non_field_errors }}
                {% for field in form %}
                        {{ field.errors }}
                {% endfor %}
            </div>
            {%endif%}

            {% csrf_token %}

            {# Include the hidden fields #}
            {% for hidden in form.hidden_fields %}
                {{ hidden }}
            {% endfor %}

            {# Include the visible fields #}
            {% for field in form.visible_fields %}

                    {{ field.label_tag }} {{ field }}
                    <span class="help-block">{{ field.help_text }}</span>

            {% endfor %}
            {% for collapsible_field in form.collapsible_fields %}
            <div class='collapsible'>
                    {{ field.label_tag }} {{ field }}
                    <span class="help-block">{{ field.help_text }}</span>                             
            </div>
            {%endfor%}
        <br />
        <input type="submit" value='{% trans 'Login' %}' class="btn" />
    </form>

the example above is to explain further my point, but i would go for any other approach.. Please advise?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:49:08+00:00Added an answer on June 8, 2026 at 12:49 pm

    The desired solution you proposed looks fine.
    Just add these in your Form class:

    class PageForm(forms.ModelForm):
        class Meta:
            model = Page
    
        def normal_fields(self):
            return [field for field in self if not field.is_hidden
                   and field.name in ('field1', 'field2')]
    
        def collapsible_fields(self):
            return [field for field in self if not field.is_hidden
                   and field.name in ('field4', 'field5', 'field3')]
    

    and then in your template just use these methods:

    {# Include the visible fields #}
    {% for field in form.normal_fields %}
    
            {{ field.label_tag }} {{ field }}
            <span class="help-block">{{ field.help_text }}</span>
    
    {% endfor %}
    {% for field in form.collapsible_fields %}
    <div class='collapsible'>
            {{ field.label_tag }} {{ field }}
            <span class="help-block">{{ field.help_text }}</span>                             
    </div>
    {%endfor%}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project whereby I'm trying to create a distribution zip file, which
I have a project whereby a large number of technical specifications are currently 'published'
i am currently working on a project where i have 'units' that will have
On a flex project, I have a slider and text box on a form
I have part of a project whereby I need to send 1 to up
I have: Project \-src/main/resources \-src/main/java \-src/test/resources \-TestDataSourceContext.xml \-src/test/java and DatabaseUtils \-src/main/resources \-src/main/java \-src/test/resources \-AbstractTestDataSourceContext.xml
I have project on recruitment.In this project, at one form I have a grid
I am working on a project, whereby I have several groups, several permissions and
I have a Django project whereby every model inherits from a common Object model
I'm working on a project whereby I have a series of configuration classes in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.