python - How to use a queryset filter with M2M models in django admin-export? -
i need export data in django admin, i'm using django-import-export
lib , export fine, problem gets id
of attribute instead of name(of course)
given models, on operation export, want book
atribute book's title
instead of id's tied operation
class book(models.model): title = models.charfield() value = models.floatfield() class operation(models.model): book = models.manytomanyfield(book, through='bookoperation') sender = models.charfield() date = models.datefield() class bookoperation(models.model): book = models.foreignkey(book) operation = models.foreignkey(operation) quantity = models.integerfield()
here operationresource
in admin.py
class operationresource(resources.modelresource): book = fields.field(column_name='book(s)', widget=manytomanywidget(book)) class meta(object): model = operation exclude = ('id',) def dehydrate_book(self, operation): return operation.book.get()
with code this, i'm getting
get() returned more 1 book -- returned 2!
i tried using operation.book.filter doesn't see work, must doing wrong !
Comments
Post a Comment