from django import forms
class CategoryAdminForm(forms.ModelForm):
class Meta:
model = Category
exclude = ['brand_name']
from django.contrib import admin
from django.db import connection
from .models import Category
from .forms import CategoryAdminForm
@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
SQL_QUERY = '...'
form = CategoryAdminForm
def get_form(self, request, obj=None, **kwargs):
form_class = super(CategoryAdmin, self).get_form(request, obj=obj, **kwargs)
with connection.cursor() as cursor:
cursor.execute(SQL_QUERY, [obj.category_id])
row = cursor.fetchone()
form_class.brand_name = forms.CharField(initial=row[0])
return form_class
Sublime text 2/3 самое оно :) Ну мне как маководу больше всего нравиться, к тому же есть целая дюжина аддонов Package control