Wow, what a quick reply! Thanks Malcolm.

I'm pretty new to Django so excuse my inability to express myself in
Django terms.

I agree with your comments regarding taking the right approach to
solving the problem (how very Pythonic of you :-)
I tried django_restapi because it offered a quick starting point for
some proof of concept prototypes which I am most likely to throw away
anyway.

When I say that I want to create a model for a custom SQL query I mean
exactly that. I would like to have a model class which behaves just
like any other model but with some exceptions:

- it would be read only
- there is no table corresponding to the model class
- when retrieving records/instances of the model a custom query is
executed instead of whatever query Django would generate
automatically.

Now, I don't know if any of that actually makes any sense. If there is
a better way then I'm all ears.

I read up on model managers but as far as I can tell a manager belongs
to a model. I don't actually have a model into which I could put a
custom manager which would manage my custom SQL. The custom SQL
statement is rather long and ugly with multiple joins. I can't clean
it up for now because that would involve cleaning up all the legacy
tables used in the query and I need to avoid that for now.

As for the example, there is not much that I can give you. I have
inherited some old code and I need to replicate its functionality. I
want to create a sort of a web service where a resource can be
accessed using its URI and it's sent back to the client in either XML
or JSON format. To that effect, all I can show you is the legacy SQL
query which I need to execute and somehow represent its result as a
QuerySet. Here it is:

    my $sql =<<SQL;
SELECT DISTINCT
    Ass.JobActualEndDate,
    Ass.JobEstEndDate,
    Ass.JobUser,
    Ass.JobStatus,
    Ass.JobTask,
    Ass.JobType,
    Ass.JobNotes,
    Ass.JobStartDate,
    DATEDIFF(Ass.JobEstEndDate, CURDATE()) AS DaysLeft,
    IFNULL(P.ScheduledFinish, A.ScheduledFinish) AS ScheduledFinish,
    IFNULL(P.ShotStatus, A.AssetStatus) AS ShotStatus,
    IFNULL(P.TargetDate, A.TargetDate) AS TargetDate,
    A.ScheduledFinish AS AssetScheduledFinish,
    Ass.ShotID,
    Ass.AssetID,
    Ass.Shot,
    Ass.Scene,
    Ass.Project
FROM
    Assignments AS Ass
    LEFT JOIN
        Production AS P USING (ShotID)
    LEFT JOIN
        Assets AS A USING (AssetID)
    LEFT JOIN
        Shots.Shots AS S ON Ass.ShotID = S.Shot_ID
WHERE
    JobUser = ?
AND Ass.JobCorrelationNumber < 10
AND Ass.JobCorrelationNumber >= 0
SQL



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to