oscarmlage / django-cruds-adminlte

django-cruds is simple drop-in django app that creates CRUD for faster prototyping
BSD 3-Clause "New" or "Revised" License
424 stars 83 forks source link

List #57

Closed fjbardelli closed 5 years ago

fjbardelli commented 6 years ago

Columns that are not model fields can be added to the list.

For example, a property that takes out an average of a field from a foreingkey.

luisza commented 6 years ago

Yes you can i think, you need to set a get_varname_display method for a field, so you create a attribute and the funtion get_attribute_display () so when list search for a field they look first for this function and print whatever it return.

Other way could be possible is using de decorator @property but try and test

oscarmlage commented 6 years ago

@fjbardelli and, please, feel free to write the result of your test. Didn't tried with properties but I think @luisza is right.

fjbardelli commented 6 years ago

with @property does not work gives the following error

Request Method: GET

http://127.0.0.1:8001/secAlumnos/examennota/list?Examen=7 1.11 FieldDoesNotExist ExamenNota has no field named 'Clase' /home/fernando/.virtualenvs/secColegio/lib/python3.6/site-packages/django/db/models/options.py in get_field, line 619 /home/fernando/.virtualenvs/secColegio/bin/python 3.6.3 ['/home/fernando/Sistemas/WebApps/secColegio', '/home/fernando/.virtualenvs/secColegio/lib/python36.zip', '/home/fernando/.virtualenvs/secColegio/lib/python3.6', '/home/fernando/.virtualenvs/secColegio/lib/python3.6/lib-dynload', '/usr/lib/python3.6', '/home/fernando/.virtualenvs/secColegio/lib/python3.6/site-packages'] Mar, 6 Mar 2018 13:47:39 +0000

And with
def _get_Clase_display(self, field): return str(Examen.Clase)

Request Method: GET

http://127.0.0.1:8001/secAlumnos/examennota/list?Examen=7 1.11 FieldDoesNotExist ExamenNota has no field named 'Clase' /home/fernando/.virtualenvs/secColegio/lib/python3.6/site-packages/django/db/models/options.py in get_field, line 619 /home/fernando/.virtualenvs/secColegio/bin/python 3.6.3 ['/home/fernando/Sistemas/WebApps/secColegio', '/home/fernando/.virtualenvs/secColegio/lib/python36.zip', '/home/fernando/.virtualenvs/secColegio/lib/python3.6', '/home/fernando/.virtualenvs/secColegio/lib/python3.6/lib-dynload', '/usr/lib/python3.6', '/home/fernando/.virtualenvs/secColegio/lib/python3.6/site-packages'] Mar, 6 Mar 2018 13:54:56 +0000

luisza commented 6 years ago

def get_clase_display(self, field): ?

how is the model ? Did have Clase() Method ?

oscarmlage commented 5 years ago

Guys take a look to 18fcc53589bc6135b28eb54f37c7e5ee70626c96, maybe the 'list_model' list can help with this. What do you think?

oscarmlage commented 5 years ago

Properties that are not fields can not be listed for now, it only looks for model.fields