A
A
Alexander2016-04-09 10:38:43
Django
Alexander, 2016-04-09 10:38:43

How to add your input in the admin?

There is a news module, but I don't want to create image fields for it in the database. How to add your input in the form from the admin panel? I searched in Google but found how to display these things in front.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2016-04-09
@kentuck1213

Something like this:
In admin.py:

from forms import ВашаФорма

@admin.register(ВашаМодель)
class ВашаМодельAdmin(admin.Modeladmin):
    form = ВашаФорма

in forms.py
class ВашаФорма(forms.ModelForm):
    ваше_поле = forms.КакойтоСтандартныйФорматПоля()

    def save(self, commit=True):
         instance = super(ВашаМодель, self).save(commit=False)
         # ...тут определяем что делаем с полем при сохранении..
         #  оно в self.cleaned_data['ваше_поле']
         if commit:
                instance.save()
         return instance

    class Meta:
        model = ВашаМодель
        fields = ('ваше_поле', 'какие-то другие поля которые нужно выводить')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question