Enable Django admin functionality in frontend with built-in

I decided to move some functions from my admin site to the interface. Functionality includes administering the same model with some external key lines.

To do this, I installed the jQuery django-dynamic-formset plugin ( git link) and have been struggling with it for a couple of days. Here is one of the problems.

The same functionality is already implemented in the Django admin. I can add, modify, delete inline strings and modify the model instance as I want. I am wondering why I should use this jQuery plugin and why there aren’t so many good tutorials on this topic on the Internet?

I need a good and recent example of using django forms or inline forms on the interface side without third-party JS files. I would be happy if it has links (not checkboxes) to remove inline elements and add a button that will correctly add a new line.

To be more specific, because the question was considered too broad:

I have two School and SchoolPlace models:

class School(models.Model): name = models.CharField(_('School name'), max_length=100) class SchoolPlace(models.Model): school = models.ForeignKey(School, verbose_name=_('school place'), related_name='school_places', blank=True, null=True) name = models.CharField(_('School place name'), max_length=200) city = models.ForeignKey(City, blank=True, null=True, verbose_name=_('city'), help_text='city') 

There are also relevant forms:

 class SchoolForm(forms.ModelForm): name = forms.CharField( label=_('Name'), widget=forms.TextInput(attrs={ 'placeholder': _('school name')}), max_length=100, required=True) class SchoolPlaceForm(forms.ModelForm): name = forms.CharField(label=_('Name'), widget=forms.TextInput( attrs={'placeholder': _('school place name')}), max_length=200, required=False) city = forms.ModelChoiceField(label=_('City'), widget=forms.Select(attrs={'class': 'ui search dropdown'}), queryset=City.objects.all(), required=False) class Meta: model = SchoolPlace fields = ['name','city'] exclude = ['school'] 

I would like to edit these two models in the same way as in Django admin, but only on my own interface. Since all js files are already in django.contrib.admin, I would like to do this without using side applications and plugins.

I need the same functions as in Django admin: add, delete, change lines in SchoolPlace. Here is a screenshot: enter image description here

+7
python django django-admin inline-formset formset
source share
2 answers

I would suggest that you used admin forms (in your views) or admin views (at custom URLs) and just changed admin templates or even just downloaded admin javascript, you can find it in admin templates.

+1
source share

This task requires support on both third and third parties.

It seems that the easiest way is to use the django-admin forms on the frontend, if that is acceptable to you.

Any django admin form recognizes the ?_popup=1 parameter in the url to suppress the scenery of the admin page and only serve the form. All necessary JavaScript and CSS styles will be included. Thus, admin forms can be displayed on the interface in an iframe . A small hack at the JavaScript level is still required to adjust the iframe size in the form and notify the page, after which the form closes.

+1
source share

All Articles