I have a design/approach question, I think it boils down to needing to join
two tables on multiple fields, where the tables are not linked via a
foreignkey.  However I'm open to any suggestions on rethinking the overall
approach to it. Here's what I'm trying to accomplish.


I have a model with fields [provider], [sheetid], [line], [column],
[value].


I would like to maintain a list of filter criteria like [filterSheet],
[filterRow], [filterColumn]. There could be 1 set of these filters, or
many. I'd like to query the main model for any values that match a filter
criteria record on sheet and row and column.


I'd like the list of filter criteria to be user maintainable, to grow over
time, so it seems to me it might be best to maintain this as a separate
model/table that users could easily add to, rather than something like a
hard coded list of tuples.  So for models, I have something like this:


class crSummary(models:Model):

    submitterID =  models.CharField(max_length = 6, unique=True)

     ....


class crDetail(models.Model):

     crsum = models.ForeignKey('crSummary', on_delete=models.CASCADE)

     sheetid = models.CharField(max_length = 7)

     line = models.DecimalField(max_digits = 5, decimal_places=2)

     column = models.DecimalField(max_digits = 5, decimal_places=2)

     value = models.DecimalField(max_digits = 11, decimal_places=2)


class tentFilter(models.Model):

     filterSheet = models.CharField(max_length =7)

     filterLine = models.DecimalField(max_digits = 5, decimal_places=2)

     filterColumn = models.DecimalField(max_digits = 5, decimal_places=2)



I can do a sql join using .raw() to join the crDetail and tentFilter tables
... "on sheetid=filterSheet and line=filterLine and column=filterColumn".
However I'm curious if there's a way to accomplish this using the ORM?  I
found "ForeignObject" but it doesn't work in this scenario as the sheetid,
line, column fields are not unique (any provider could potentially have a
given sheet, line, column combination which I am trying to extract via the
filter).


Is there a way to achieve ForeignObject type functionality but with many to
many relationships?


Any help would be greatly appreciated.  Thanks!


-Sam

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAC1pHu4TzbJ6qM%2Br7MavML6eASajSWF9vf39iiAoTQ2FSdbJvw%40mail.gmail.com.

Reply via email to