These are chat archives for django/django

14th
Nov 2018
Mathieu Hinderyckx
@mhindery
Nov 14 2018 09:35
You definitely don't "need" it, it has upsides and downsides. It offers some nice implementations and 'third-party' for authentication, permissions ... The serialization is a nice standardized way to define serialization on your models, and the view structure it provides are also often clearly defined. It gives you an out-of-the-box web UI for working with you api (very useful in development), automatic doc generation (e.g. openapi spec). Disadvantages I found are that you often need to write complex serializers and/or view constructs as soon as you want anything out of the ordinary, it doesn't play well with your model clean methods... It also can use some automatic versioning based on url's but that requires a rather strict and complex structure of your routes.
If you start from scratch and don't have too much complex requirements foreseen, i'd be sure to look at it. But know that it can quickly become rather complex and a lot of work which does not resemble the "clean, quick, easy" examples in their docs :)
Constantine
@unk2k
Nov 14 2018 17:41
Hi all! I have a SQL function which return data as a table. I want to create django model based class which fields equal a table which return my SQL function. How can I hack a queryset class to replace functional call to raw sql?
Not sure it will work but that's where I'd start...
Constantine
@unk2k
Nov 14 2018 19:42
it's not what I'm talking about.
:\
AJ
@ajostergaard
Nov 14 2018 19:43
Then I don't understand the question - care to clarify?
"This method takes a raw SQL query, executes it, and returns a django.db.models.query.RawQuerySet instance." sounds to me like what you are asking.
Constantine
@unk2k
Nov 14 2018 19:45
You advice me to create a method which can call a SQL function. I want to use this model in Paginator and similar modules. This modules can use filter, exclude, limit and etc. I want to catch that all on the last step, and made my own call, goten result can be converted to model instance.
AJ
@ajostergaard
Nov 14 2018 19:46
No - I advised you to read about Managers... :)
Constantine
@unk2k
Nov 14 2018 19:46
last step — it's iter method of ModelIterable class.
I read about Managers before I come here.
AJ
@ajostergaard
Nov 14 2018 19:47
"This RawQuerySet instance can be iterated over just like a normal QuerySet to provide object instances."
If that doesn't help you then I am sorry - just hope somebody else here understands the need and can help. Good luck.
Constantine
@unk2k
Nov 14 2018 19:48
django pagination module execute additional queries like count and etc.
Thanks you AJ for your time and your help.
AJ
@ajostergaard
Nov 14 2018 19:50
:)
Constantine
@unk2k
Nov 14 2018 19:51
my current idea is override methods "getitem" and "len" on base models class. And using Model class instead of queryset. black magic, I don't like it :\
very interesting, why people didn't made a code for this.
Like if I want to change datasource from database to API restful or something like this.
someone advice to write own database backend
but it's also black magic.
there is a lot of black magic when we talking about django orm.
Himanshu Shankar
@iamhssingh
Nov 14 2018 20:00

Like if I want to change datasource from database to API restful or something like this.

The whole point of ORM is that it’s a OOPS - RDMS Mapping

I still don’t understand what you want to achieve. Probably a sample code can help.
What I can understand from your question, I believe @ajostergaard has already answered your query.
Constantine
@unk2k
Nov 14 2018 20:36
to be easy explain, I want to use django ORM but the backend should work through RESTful API.