1

Is there a model field to create a list of bullet points in Django? Like you would do for specifications of a product? If not how would I do this?

Example

Specifications:
- feature 
- feature
- feature
- feature

I don't have any code to show as I don't know where to start. I haven't found anything online of what I'm looking for.

GTA.sprx
  • 817
  • 1
  • 8
  • 24
  • are you talking about an html [unordered list](https://www.w3schools.com/HTML/html_lists.asp)? You can do that with [`Form.as_ul()`](https://docs.djangoproject.com/en/2.2/topics/forms/#form-rendering-options) – Lord Elrond Oct 31 '19 at 00:01
  • I think Django Choice-Field will work for you, for more details -[check this](https://stackoverflow.com/questions/24403075/django-choicefield/24404791) – Anant Sabale Oct 31 '19 at 09:24

1 Answers1

1

You don't need a model field for the html representation. Model fields are mainly for database. Any field data can be shown in bullet points because bullet points are the part of styling they have nothing to do with data type (model field). Read bootstrap4 documentation or watch a beginner tutorial on "List Groups bootstrap4".

Nonetheless, Below code works fine for the simple bullet points representation in html.

<ul class="list-group">
  <li class="list-group-item">First item</li>
  <li class="list-group-item">Second item</li>
  <li class="list-group-item">Third item</li>
</ul> 

Below code is another possible way of writing above code in django html page

<ul class="list-group">
  <li class="list-group-item" id='product'>{{ form.product }}</li>
  <li class="list-group-item" id='price'>{{ form.price}}</li>
  <li class="list-group-item" id='discount'>{{ form.discount}}</li>
</ul>

Example:

forms.py

from django import forms

class product(forms.Form):
    productname= forms.CharField(label='ProductName', max_length=100)
    price= forms.IntegerField(label='5')
    discount= forms.IntegerField(label='5')

loginpage.html

<ul class="list-group">
  <li class="list-group-item" id='product'>{{ form.product }}</li>
  <li class="list-group-item" id='price'>{{ form.price}}</li>
  <li class="list-group-item" id='discount'>{{ form.discount}}</li>
</ul>