Skip to main content

A Django app to conduct web-based bootstrap5, select2, CRUD, TABLE.

Project description

Modulo es una aplicacion de Django Para implementar el crud y tablas en bootstrap 5.2

Detailed documentation is in the “docs” directory.

Quick start

  1. Add “modulo” to your INSTALLED_APPS setting like this:

    pip install django-bootstrap5-modulo
    
    add in settings.py
    
    INSTALLED_APPS = [
        ...
        'modulo',
    ]
  2. Include the modulo URLconf in your project urls.py like this:

    path('modulo/', include('modulo.urls')),
  3. Run python manage.py migrate to create the modulo models.

  4. Start the development server and visit https://github.com/xcarlx/plugin_django.git to create a poll (you’ll need the Admin app enabled).

  5. Visit https://pypi.org/project/django-bootstrap5-modulo/ to participate in the poll.

Configuration

  1. Configure template base:

    <head>
       ...
       {% include 'modulo/formulario/styles.html' %}
    </head>
    <body>
       ...
       {% include 'modulo/formulario/modal.html' %}
       {% include 'modulo/formulario/scripts.html' %}
    </body>
  2. Configure class view CRUD:

    Configure forms
    class FormClass(forms.ModelForm):
        ...
    
        def __init__(self, *args, **kwargs):
            super(FormClass, self).__init__(*args, **kwargs)
            for field in self.fields:
                self.fields[field].widget.attrs['class'] = "form-control"
    
    Configure ClassView
    class ClassView(CreateView): # UpdateView, FormView
        ...
        template_name = "modulo/formulario/formulario.html"
        success_url = reverse_lazy('modulo:success', args=[0]) # or add in models get_absolute_url -> return reverse('modulo:success', kwargs={'pk': self.pk})
    
    
    class EliminarView(DeleteView):
        ...
        template_name = "modulo/formulario/eliminar.html"
        success_url = reverse_lazy('modulo:success', kwargs={'pk': 0})
  3. Configure ListView

    * Create html table.html
    
    class ListaView(ListView):
        ...
        template_name = "table.html"
    
        def get_queryset(self):
            query = super(ListaView, self).get_queryset()
            search = self.request.GET.get("search")
            if search:
                query = query.filter(
                    Q(name__icontains=search) |
                    Q(othername__icontains=search)
                )
            return query
    
    * Configure tamplate table.html
    
    {% extends 'modulo/formulario/lista.html' %}
    {% block titulo %}
    
    {% endblock %}
    {% block contenido_tabla %}
        <thead>
            <tr>
                <th class="text-center">HEAD</th>
            </tr>
        </thead>
        <tbody>
            {% for object in page_obj %}
                <tr>
                    <td class="text-center"> {{ object.name }}</td>
                    <td>
                        <div class="btn-group">
                            <button class="btnEditar btn btn-primary btn-sm" data-pk="{{ object.pk }}"><span
                                    class="bi bi-pen"></span></button>
                            <button class="btnEliminar btn btn-danger btn-sm" data-pk="{{ object.pk }}"><span
                                    class="bi bi-trash"></span></button>
                        </div>
                    </td>
                </tr>
            {% endfor %}
        </tbody>
    {% endblock %}
    
    {% block paginacion %}
    
    {% endblock %}
  4. Configure basic JAVASCRIPT CRUD and LIST:

    <script type="module">
        import Modulo from "{% static 'modulo/js/modulo.js' %}";
        import ListaView from "{% static 'modulo/js/lista.js' %}";
    
        const formulario = document.getElementById("formModal"); {# get form #}
        const modal = document.getElementById("modalForm"); {# get modal #}
        const content = document.getElementById("contentElement"); {# content in to load table #}
    
        const modulo = new Modulo();
        const lista = new ListaView(modulo, content, "{% url 'url_listview' %}");
    
        lista.post_cargar_lista = () => {
            lista.botones("{% url 'url_create' %}", "{% url 'url_edit' 0 %}","{% url 'url_delete' 0 %}", "Test")
        }
    
        formulario.onsubmit = ev => lista.submit(ev);
    </script>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-bootstrap5-modulo-0.1.4.1.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_bootstrap5_modulo-0.1.4.1-py3-none-any.whl (3.3 MB view details)

Uploaded Python 3

File details

Details for the file django-bootstrap5-modulo-0.1.4.1.tar.gz.

File metadata

File hashes

Hashes for django-bootstrap5-modulo-0.1.4.1.tar.gz
Algorithm Hash digest
SHA256 7570ba764c05ad17911b986b1c7482d6d4c1ea03fde573e3a7c20c7cec397079
MD5 740df4bb8c54cf289b22039ef1dc31da
BLAKE2b-256 7eab90bb3ac467e76722881ef95c2f365fdf11dc89ce367bd5d8b35343b97f1c

See more details on using hashes here.

File details

Details for the file django_bootstrap5_modulo-0.1.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_bootstrap5_modulo-0.1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a3b89ac0708433cb4c7e3ce03bd021ea2af0629648ad47b733e2042d0395b447
MD5 be249b073cb7c6fbb48ed55172107041
BLAKE2b-256 fdf1c10cb745e0d656aa97981128c8bd1f452c75354376c712a28950dca11dea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page