Skip to content

Instantly share code, notes, and snippets.

@asadlive84 asadlive84/admin.py
Created Sep 20, 2018

Embed
What would you like to do?
from django.forms import ModelForm
from django import forms
class ChildInlineFormSet(BaseInlineFormSet):
'''
def __init__(self, *args, **kwargs):
super(ChildInlineFormSet, self).__init__(*args, **kwargs)
# Now we need to make a queryset to each field of each form inline
self.queryset = Marks.objects.filter(subject_name__subjet_class=10).order_by('-subject_name')
print(self.queryset)
'''
def __init__(self, *args, **kwargs):
super(ChildInlineFormSet, self).__init__(*args, **kwargs)
self.initial = [{ 'name': 's1', }, {'name': 's2'},]
class ServerInlineAdminForm(ModelForm):
class Meta:
model = Marks
fields=('__all__')
def __init__(self, *args, **kwargs):
super(ServerInlineAdminForm, self).__init__(*args, **kwargs)
#self.initial['subject_name__subject_name']='Testing'
self.fields['std_name'].queryset = Marks.objects.filter(subject_name__subjet_class='Six')
#self.queryset = Marks.objects.filter(subject_name__subject_name__startswith='O')
class MarksSubjectInstanceInline(admin.TabularInline):
model = Marks
#form = ServerInlineAdminForm
#fk_name = 'std_name'
author='std_name'
#formset = ChildInlineFormSet
extra = 1
exclude = ['subject_gradepoint', 'subject_gpa','subject_gpa_sub', 'subject_marks', 'subject_total_marks']
@admin.register(StudentInfo)
class StudentAdmin(admin.ModelAdmin):
list_filter = ('std_class', 'std_gender', 'std_group',)
list_display = ('std_name', 'std_class', 'std_group', 'std_gender', 'std_roll')
inlines = [MarksSubjectInstanceInline]
search_fields = ('std_name','std_roll','std_group')
exclude = ['std_total_marks', 'std_gpa','std_grade_point_total_sum','std_marks_with_fail_sub', 'std_grade_point_total_subject_avg', 'std_fail_subject','school_rank','class_rank']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.