Answer the question
In order to leave comments, you need to log in
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
Something like this:
In admin.py:
from forms import ВашаФорма
@admin.register(ВашаМодель)
class ВашаМодельAdmin(admin.Modeladmin):
form = ВашаФорма
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 questionAsk a Question
731 491 924 answers to any question