I'm a beginner in Django3 and just wrote an overview function to pass on some data to the template in a context variable.

I am definitely passing a lot more than I should as I only need only a few fields from each of these variables. Also, it might not be the most Django-esque way of doing things as it isn't using GenericViews or any of the more advanced Django features.

please review, comment, and provide suggestions or modifications:

def overview_page(request):
    user = request.user
    org = Organization.objects.filter(user=user)
    projects = Project.objects.filter(organization=org[0])
    # get first is_active project, as this is only allowed once per
    #    Organization. The model will need to be fixed post MVP for better 
    #    design 
    active_project = Project.objects.filter(organization=org[0],
    assets = Asset.objects.filter(project=active_project)
    functional_classes = FuncClass.objects.filter(project=active_project)
    conditions = Condition.objects.filter(project=active_project)
    det_curves = DetCurve.objects.filter(project=active_project)
    func_classes = FuncClass.objects.filter(project=active_project)
    model_settings = ModelSettings.objects.filter(project=active_project)
    scenarios = Scenario.objects.filter(project=active_project)
    surface_types = SurfaceType.objects.filter(project=active_project)
    treatments = Treatment.objects.filter(project=active_project)

    context = {'user': user,
               'my_org': org[0],
               'func_class': functional_classes,
               'projects': projects,
               'active_project': active_project,
               'assets': assets,
               'conditions': conditions,
               'det_curves': det_curves,
               'func_classes': func_classes,
               'model_settings': model_settings,
               'scenarios': scenarios,
               'surface_types': surface_types,
               'treatments': treatments,

    return render(request, 'asset_manager/overview.html', context)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.