0

I am looking for a way to implement the "add new model_name" functionality from Django admin to normal form in templates, i.e; outside of Django admin, how could I use the same functionality.

enter image description here

How could I achieve it?

Maverick
  • 2,738
  • 24
  • 91
  • 157

1 Answers1

0

The first Step is to create Business Module inside models.py

class Business(models.Model):
        name = models.CharField(max_length=200, db_index=True)
        slug = models.SlugField(max_length=200, db_index=True, unique=True)

        class Meta:
            ordering = ('name',)
            verbose_name = 'business'
            verbose_name_plural = 'business'

        def __str__(self):
            return self.name

Then use python manage.py migrate to migrate module inside your database.

Now open admin.py file and register this Module,

from .models import Business

# Register your models here.
class BusinessAdmin(admin.ModelAdmin):
    list_display = ['name', 'slug']
    prepopulated_fields = {'slug': ('name',)}
admin.site.register(Business,BusinessAdmin)

Now check your Django admin panel. It will show you New Business Module there with Add, remove feature using Form.

I hope this will helpful for you.

Ahmed Ginani
  • 6,522
  • 2
  • 15
  • 33
  • I think I have not made it clear in the description. I am sorry, but I am looking for a way to replicate it outside of Django admin in normal templates which is used to fill the form and not inside Django admin. – Maverick Apr 27 '17 at 12:43