В принципе решил задачу
models.py:
class Shedule(models.Model):
week=models.ForeignKey(Week)
section=models.ForeignKey(Section)
teacher=models.ForeignKey(Teacher)
lesson_time_start=models.TimeField()
lesson_time_finish=models.TimeField()
Подгружаю свои скрипты для модели
admin.py:
class ScheduleAdmin(admin.ModelAdmin):
class Media:
js = (
'/static/js/jquery-1.4.3.js',
'/static/js/adminAjax.js',
)
adminAjax.js:
$(document).ready(init);
function init(){
$('#id_section').change(function() {
if ($('#id_section').val()!=""){
$.post("/adminAjax/", {"id_section":$('#id_section').val()}, function(text){
$('#id_teacher').html(text);
});
}
});
}
Сделал вьюху в проекте:
@csrf_exempt
def admin_ajax(request):
if request.user.is_superuser:
if request.method == 'POST':
from schedule.models import Section
if request.POST["id_section"]:
section=Section.objects.get(id=request.POST["id_section"])
teachers=section.teacher.all()
html='---------'
for teacher in teachers:
html=html + '%s' %(teacher.id, teacher)
return HttpResponse(html)
Есть что сказать в плане "как сделать лучше/правильнее"?