P
P
paevlk20072014-08-01 14:29:12
Django
paevlk2007, 2014-08-01 14:29:12

Django how to solve smart_select id problem, pandas?

Models.py
from django_pandas.managers import DataFrameManager

class Accessories(models.Model):
    created_on = models.DateTimeField(u"Дата создания", auto_now_add=True, editable=True, blank=True, null=True)
    posted_by =  models.ForeignKey(User, blank=True, null=True)
    edited_by = models.CharField(max_length=255, blank=True)
    accessories_plot = models.ForeignKey(Accessories_plot, verbose_name='Участок', blank=True, null=True)
    accessories_view_eq = ChainedForeignKey(Accessories_view_eq, chained_field = "accessories_plot", chained_model_field = "accessories_plot", show_all = False, auto_choose = True, verbose_name='Оборудование', blank=True, null=True)
    accessories_node = ChainedForeignKey(Accessories_node, chained_field = "accessories_view_eq", chained_model_field = "accessories_view_eq", auto_choose = True, verbose_name='Узлы оборудования', blank=True, null=True)
    accessories_work =  ChainedForeignKey(Accessories_work, chained_field = "accessories_node", related_name='accessories_works', chained_model_field = "accessories_node", verbose_name='Работы', blank=True, null=True)

objects = DataFrameManager()

Views.py
def accessories_work_otchet(request, template_name="accessories_work_otchet.html"):
    qs = Accessories.objects.filter(workers=10).all()
    rows = ['accessories_work', 'accessories_works']
    cols = [ 'access_date_perfor', 'workers']
    df = qs.to_pivot_table(values='access_time_total', aggfunc=np.sum, rows=rows, cols=cols, margins=True, dropna=True, verbose=True, fill_value='')
    qw = df.to_html(index=True, classes='')
    ctx = {'qw': qw}
    return render(request, template_name, ctx)

The problem is that the fields with models.ForeignKey in the report (to_html) reflect the names, the fields with ChainedForeignKey reflect the id of this field.
Help!!! Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question